Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 拉广告组并统计每个组中的用户数_Powershell - Fatal编程技术网

Powershell 拉广告组并统计每个组中的用户数

Powershell 拉广告组并统计每个组中的用户数,powershell,Powershell,我想拉一个OU中的所有广告组,然后打印出每个组以及该组中的用户数。按照我目前的方式,它只计算组名和成员数 Import-Module ActiveDirectory $groups = (Get-ADGroup -Filter {GroupCategory -eq 'security'} -SearchBase 'Path to OU' | select SamAccountName).samaccountname foreach ($group in $groups){ (Get-ADGrou

我想拉一个OU中的所有广告组,然后打印出每个组以及该组中的用户数。按照我目前的方式,它只计算组名和成员数

Import-Module ActiveDirectory
$groups = (Get-ADGroup -Filter {GroupCategory -eq 'security'} -SearchBase 'Path to OU' | select SamAccountName).samaccountname
foreach ($group in $groups){
(Get-ADGroup -Identity $group | select name).count
 }

使用
members
属性,并对其进行计数

Import-Module ActiveDirectory
$groups = Get-ADGroup -Filter {GroupCategory -eq 'security'} -SearchBase 'Path to OU' -Properties *
foreach ($group in $groups) {$group.members.count}
或者,既然你两者都想要

$groups | select name, {$_.members.count}

使用
members
属性,并对其进行计数

Import-Module ActiveDirectory
$groups = Get-ADGroup -Filter {GroupCategory -eq 'security'} -SearchBase 'Path to OU' -Properties *
foreach ($group in $groups) {$group.members.count}
或者,既然你两者都想要

$groups | select name, {$_.members.count}