代码之家  ›  专栏  ›  技术社区  ›  LeeM

广告中大群体的快速查询

  •  1
  • LeeM  · 技术社区  · 7 年前

    我想找出一种更有效的方法来用Powershell识别大型广告群(比如5000多个用户)。不需要列出成员,因为我想 排除 这些组来自另一个进程。

    Get-ADGroup

    (Get-ADGroup "Group" -Properties members).members.count | where {$_ -lt 5000}
    

    1 回复  |  直到 7 年前
        1
  •  0
  •   Robert Cotterman    7 年前

    我没有确切的答案。但是你要求DC告诉你所有会员的名字不管怎样。这需要很长时间。get adgroup的括号要求查询每个成员并将其保存在本地ram中。然后你告诉它获取成员的方法。所以它重温它。然后数一数。

    如果你这么做的话。它会并行运行,而不是重复两次。这样可以节省20-30%的时间。

     Get-ADGroup "Group" -Properties members | select -ExpandProperty members | measure | where count -lt 5000
    

    下面是一个自动执行此操作的示例脚本。。。(我更改了ldap筛选器)

    Get-ADGroup -filter * | select -expand name | foreach { 
        $group = $_
        if (Get-ADGroup {name -eq $group} -Properties members | select -ExpandProperty members | measure | where count -lt 5000){
            $countedGroups += $group
        }
        $countedGroups
    }