我一直想弄清楚如何获取所有空的 Active Directory 组。我想出了这个命令,它选择没有成员且不是任何成员的组。
Get-QADGroup -GroupType Security -SizeLimit 0 | where-object {$_.Members.Count -eq 0 -and $_.MemberOf.Count -eq 0} | select GroupName, ParentContainer | Export-Csv c:\emptygroups.csv
这基本上是正确的,但它说某些组,如默认组 Domain Computers 是空的,但它不是空的。这个特定组只有计算机成员,但似乎没有选择其他只有计算机的组。
有谁知道为什么这个命令会吸引一些有成员的人?
最佳答案
Get-QADGroup
cmdlet 有一个参数 -Empty
。帮助中的描述提示了这些默认组被返回的原因:
Note: A group is considered empty if it has the "member" attribute not set. So, this parameter can retrieve a group that has only those members for which the group is set as the primary group. An example is the Domain Users group, which normally is the primary group for any user account while having the "member" attribute not set.
我不是很熟悉 Quest 的东西,但我能够通过这种方式找到空组(可能不是最有效的):
Get-ADGroup -Filter {GroupCategory -eq 'Security'} | ?{@(Get-ADGroupMember $_).Length -eq 0}
关于powershell - 获取 Active Directory 中的所有空组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11941929/