简体   繁体   English

多个广告组的总用户总数

[英]Sum of the total users of multiple AD groups

I've been trying to get the total number of users in several active directory groups and so far I've gotten this put together: 我一直在尝试获取几个活动目录组中的用户总数,到目前为止,我已经将其汇总在一起:

$Groups = Get-Content -Path $someFile
foreach ($Group in $Groups) {
    (Get-ADGroup $Group -Properties *).Member.Count
}

Of course, this spits out a number for each individual group, but I haven't come across any way of having ps add these numbers up and display the final total instead. 当然,这会为每个单独的组吐出一个数字,但是我没有碰到任何让ps将这些数字加起来并显示最终总数的方法。

I don't have access to an AD server to test this, but this should work by assigning the member count to a variable and adding the total of the current group to the variable, then output the total count when complete. 我无权访问AD服务器来对此进行测试,但这应该可以通过将成员计数分配给变量并将当前组的总数添加到变量中,然后在完成时输出总数来解决。

$Groups = Get-Content -Path
Foreach ($Group in $Groups) {
    $totalusers += (Get-ADGroup $Group -Properties *).member.count
}
$totalusers

To get the count of unique members you could do something like this: 要获得唯一成员的数量,您可以执行以下操作:

$script:cnt = 0
$Groups |
    Get-ADGroupMember |
    Select-Object -Expand DistinguishedName -Unique |
    ForEach-Object { $script:cnt++ }

If you want to resolve group members recursively (ie the members of nested groups as well) add -Recursive to Get-ADGroupMember . 如果要递归解析组成员(即嵌套组的成员),则将-Recursive添加到Get-ADGroupMember

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM