PowerShell script block to list all members from a list of groups

This will loop through the groups that it finds that match the “like” section of the script, then output the users from each group with headings to separate. The formatting could be cleaned up a bit on output, but…….meh it works.

$groups = Get-ADGroup -filter {SamAccountName -like "*GROUPNAMEHERE*"}
For ($i=0; $i -lt $groups.Length; $i++){
write-host ------------------------
Get-ADGroupMember $groups[$i] | select SamAccountName
write-host ************************

Leave a Reply

Your email address will not be published. Required fields are marked *