Easily retrieve an Active Directory group membership’s recursive user list with PowerShell.

You can easily retrieve an Active Directory group membership’s recursive user list with PowerShell.

This three-line PowerShell command will retrieve all users in the Domain Admins group, and all users’s in that group’s groups, without returning the groups themselves. I wrote this script to get a head-count showing how many users needed to be licensed for a software purchase, so I did not want to count groups. Change “Domain Admins” to your group’s name.

$ADGroupName = "Domain Admins"
$ADGroupMembers = Get-ADGroupMember -Identity $ADGroupName -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties * }

$ADGroupMembers `
| Select-Object SamAccountName, Enabled, DisplayName, EmailAddress, Created, Modified, LastLogonDate, AccountExpirationDate, `
CanonicalName, DistinguishedName, CN, Description, EmployeeID, Company, Department `
| Export-Csv -Path C:\temp\GroupMembersRecursive.csv -NoTypeInformation

$ADGroupMembers.Count

Get Group Count

Get Group Count


Leave a Reply

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

15 + eighteen =