Question
I have an Active Directory (AD) group which contains a lot of group members and also SUBGROUPS. I need to list all of them out. I am testing below cmdlet but it stops when listing subgroup’s member.
Import-Module ActiveDirectory
Get-ADGroupMember -Identity "account operators" | Get-ADUser -Property name, UserPrincipalName |Select-Object name, UserPrincipalName
I like to know how to list the group members name, UPN, subgroup name and indicate the name as subgroup?
Solution
This will have column ObjectClass, which will be either user or group:
Get-ADGroupMember -Identity "Account Operators" |
Get-ADObject -Property SamAccountName, UserPrincipalName |
Select-Object -Property Name, SamAccountName, UserPrincipalName, ObjectClass, DistinguishedName