I have a "Parent" ADGroup (ADParent
) which has multiple ADGroups as members (ADChild1
, ADChild2
).
I would like to list all ADChilds for the ADParent but filter keep only the ADChild with name containing "1"
This will list ALL members:
Get-AdGroupMember ADParent | select Name
This does not work:
Get-AdGroupMember ADParent | select Name | -Filter Name -like "1"
Any suggestions?
CodePudding user response:
Use the Where-Object
cmdlet to filter a stream of output from another cmdlet:
Get-ADGroupMember ADParent |Where-Object Name -like '*1*' |Select Name
CodePudding user response:
Another alternative querying AD for groups where their MemberOf
property contains the parent group:
$parentDN = (Get-ADGroup ParentGroup).DistinguishedName
Get-ADGroup -LDAPFilter "(&(Name=*1*)(MemberOf=$parentDN))" | Select-Object Name