Problème with variable

Welcome Forums General PowerShell Q&A Problème with variable

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #170086

    Participant
    Topics: 1
    Replies: 1
    Points: 15
    Rank: Member

    Hello,

     

    I try to use variable in -filter with * but i don't find the good syntax maybe someone can help me ?

    try this powershell :

    display a users who have variable in his name

    get-asuser -filter {name -like *$group*} not work NEED THIS

    get-asuser -filter {name -like $group}work but without *

    get-aduser -filter {name -like "*sale*"} work but i need replace sale by a variable ....

    THX !

     

     

  • #170101

    Participant
    Topics: 1
    Replies: 1
    Points: 15
    Rank: Member

    i have find a replace "solution" 🙂

    put my variable in a new one with * after and before and it work ... if someone have the "true" and proper syntax respond this post with

    $test = "*$group*"

    get-asuser -filter {name -like $test} (result,  get-aduser -filter -like *sale*, if group=sale)

  • #170131

    Participant
    Topics: 2
    Replies: 482
    Points: 1,146
    Helping Hand
    Rank: Community Hero

    Despite all the cmdlets' help documentation on -Filter, braces aren't the best syntax. Very restrictive in what you can / can't do.

    Get-ADUser -Filter "name -like '*$test*'"

You must be logged in to reply to this topic.