I need to return all members of several security groups using PowerShell. Conveniently, all groups begin with the same letters.
I can return a list of all relevant security groups using the following code:
Get-ADGroup -filter 'Name -like"ABC*"' | Select-Object Name
And I know that I can return a list of members of a specific security group using the following code:
Get-ADGroupMember "Security Group Name" -recursive | Select-Object Name
However, I cannot present them together, although I think that what I need should look something like this (please feel free to correct me, why am I here!):
$Groups = Get-ADGroup -filter 'Name -like"ABC*"' | Select-Object Name ForEach ($Group in $Groups) {Get-ADGroupMember -$Group -recursive | Select-Object Name
Any ideas on how to properly structure will be appreciated!
Thanks,
Chris
Chris source share