Get-ADGroup does not return anything if search string is stored in a variable

Welcome Forums General PowerShell Q&A Get-ADGroup does not return anything if search string is stored in a variable

Viewing 1 reply thread
  • Author
    Posts
    • #227224
      Participant
      Topics: 2
      Replies: 4
      Points: 49
      Rank: Member

      This one has me flummoxed. Here is what i am doing.

      1. Save search string in a variable
      $currAccount = "aws-eis-" + $account + "*Network-Admins*"
      $currAccount
      aws-eis-229759325811*Network-Admins*
      
      

      2. Query using Get-ADGroup cmdlet, does not return anything

      Get-ADGroup -filter {Name -like "$currAccount"}
      
      

      3. If i run Get-ADGroup using the exact search string, result obtained.

      PS C:\> Get-ADGroup -filter {Name -like "aws-eis-229759325811*Network-Admins*"}
      
      DistinguishedName : CN=aws-eis-229759325811_zoominterop-prd-Network-Admins,OU=Non-Regulated,OU=Automated,OU=Security,OU=Groups,OU=Objects,DC=ABC,DC=XYZ,DC=com
      
      

      What am i doing wrong ?

      • This topic was modified 3 weeks, 2 days ago by Prakash Jha.
    • #227257
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP
      $currAccount = 'aws-eis-' + $account + '*Network-Admins*'
      Get-ADGroup -filter 'Name -like "$currAccount"'
Viewing 1 reply thread
  • You must be logged in to reply to this topic.