Problème with variable

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

Viewing 2 reply threads
  • 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: 513
      Points: 1,322
      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*'"
Viewing 2 reply threads
  • The topic ‘Problème with variable’ is closed to new replies.