Active Directory
A set of directory-based technologies included in Windows Server.
6,937 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
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.
Something like this?
Get-ADGroup -filter "name -like '*_*'" | # matches _ABC, ABC_, ABC_DEF . . . I.E., anything with a _ character in the name
ForEach-Object{
$n = $_.name
$m = @()
Get-ADGroupMember $_.DistinguishedName |
ForEach-Object{
$m += $_.SamAccountName
}
[PSCustomObject]@{
GroupName = $n
Members = $m -join ";"
}
} | Export-Csv c:\junk\mem.csv -NoTypeInformation