Как насчет того, чтобы сделать что-то похожее на любое из следующего ...
### Show User and AD group membership
# Get users with all their properties and their group membership, display user and group name
ForEach ($TargetUser in (Get-ADUser -Filter * -Properties *))
{
"`n" + "-"*12 + " Showing group membership for " + $TargetUser.SamAccountName
Get-ADPrincipalGroupMembership -Identity $TargetUser.SamAccountName `
| Select Name
}
# Get users with base properties and their group membership, display user and group name
ForEach ($TargetUser in (Get-ADUser -Filter *))
{
"`n" + "-"*12 + " Showing group membership for " + $TargetUser.SamAccountName
Get-ADPrincipalGroupMembership -Identity $TargetUser.SamAccountName `
| Select Name
}
# Get user and AD group info, display user and group name
Get-ADUser -Filter "*" -SearchBase "CN=Users,DC=contoso,DC=com" `
-SearchScope OneLevel -Properties Name, MemberOf `
| Select-Object Name, @{Label="Memberof";
expression={($_.memberof `
| Get-ADGroup `
| Select-Object -ExpandProperty Name) -Join ","}}
Get-ADUser -Filter "*" -SearchBase "CN=users,DC=contoso,DC=com" `
-SearchScope OneLevel -Properties Name, MemberOf |
Select-Object Name, @{Label="Memberof";
expression={($_.memberof | Get-ADGroup `
| Select-Object -ExpandProperty Name) -Join ","}} `
| Format-List
Конечно, отформатируйте по необходимости.