如何在树结构中使用PowerShell输出Active Directory组的成员资格?我使用的是Windows Server 2012.它应该将父组与子组匹配。
例如:
Groups Member of
Group-1 Test group-1
Test group-2
Group-2 Test group-3
Test group-4
答案 0 :(得分:0)
您可以使用Get-ADPrincipalGroupMembership
获取群组对象的群组成员资格:
$Groups = Get-ADGroup -filter *
$output = foreach ($Group in $Groups) {
$GroupMemberships = Get-ADPrincipalGroupMembership $Group
if ($null -ne $GroupMemberships) {
foreach ($GroupMembership in $GroupMemberships) {
[pscustomobject]@{
Group = $Group.Name
Memberof = $GroupMembership.Name
}
}
} else {
[pscustomobject]@{
Group = $Group.Name
Memberof = "None"
}
}
}
$output | Format-Table
$output | export-csv C:\example.csv -notypeinformation