AD Script to get all members of groups with same naming convention

EliseF 0 Reputation points


I am trying to run a script to tell me all the members of groups that start with a certain naming convention.
I basically want to combine Get-ADGroupMember with Get-ADGroup -Filter {name -like "*_"}

So i want a query to pull all members of groups that start with lets say "ABC" --would want the group name and all members exported.

Any help would be greatly appreciated.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,838 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,041 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points

    Something like this?

    Get-ADGroup -filter "name -like '*_*'" |    # matches _ABC, ABC_, ABC_DEF . . . I.E., anything with a _ character in the name
            $n = $
            $m = @()
            Get-ADGroupMember $_.DistinguishedName |
                    $m += $_.SamAccountName
                GroupName = $n
                Members = $m -join ";"
        } | Export-Csv c:\junk\mem.csv -NoTypeInformation
    0 comments No comments