Powershell 拉广告组并统计每个组中的用户数
我想拉一个OU中的所有广告组,然后打印出每个组以及该组中的用户数。按照我目前的方式,它只计算组名和成员数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
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}