September 1, 2015 at 1:01 pm
Using the Quest AD cmdlets, this easily returns all groups with underscores around the $Code.
Get-QADGroup "*`_$Code`_*"
How can this be done with Get-ADGroup (ie, not using the Quest cmdlets, which not everyone has).
The -Filter parm only accepts the * wildcard. Help says to use LDAPFilter parm, but I can't seem to get it right:
Get-ADGroup -LDAPFilter {(name="*_$Code_*")} is not working
Thanks!
September 1, 2015 at 1:26 pm
this is working for me:
Import-Module ActiveDirectory
Get-ADGroup -Filter {Name -like '*SQL*'} -Properties * | select -property SamAccountName,Name,Description,DistinguishedName,CanonicalName,GroupCategory,GroupScope,whenCreated
Lowell
September 2, 2015 at 5:02 am
$Code = "GOL"
This returns all the groups having "GOL" in their names:
Get-QADGroup "*$Code*"
This returns all the groups having _GOL_ in their names:
Get-QADGroup "*`_$Code`_*"
Both of these return nothing:
Get-ADGroup -Filter {Name -like '*$Code*'}
Get-ADGroup -Filter {(name -like "*$Code*")}
September 2, 2015 at 5:27 am
My guess is that the Get-QADGroup cmdlet detects the variable in the middle of the search string, whereas Get-ADGroup treats it as a literal. You'll need to find a way to build the string so that it preserves the variable.
John
September 2, 2015 at 5:35 am
John: You're right about the variable not substituting. The literal "*_GOL_*" returns the correct list.
Any ideas how to make this work?
September 2, 2015 at 5:58 am
I imagine you'll have to concatenate, something like this:
'*' + $Code + '*'
I don't use Powershell all that much so I'm afraid I don't know the exact syntax off the top of my head.
John
September 2, 2015 at 6:04 am
Got it:
$Code = "*_GOL_*"
Get-ADGroup -Filter {(name -like $Code)} | select -ExpandProperty name
Thanks!
June 12, 2019 at 8:38 pm
guys....
String: "blah blah blah"
text: 'blah blah blah'
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply