gpt4 book ai didi

powershell - 计算Active Directory用户

转载 作者:行者123 更新时间:2023-12-03 00:11:55 25 4
gpt4 key购买 nike

下面的代码应该用于对用户进行计数和比较,并输出总计数,但是不知何故结果为空。我需要做什么来修复它?

$groups = $A_group, $B_Group
$gm = @()

foreach ($group in $groups) {
$gm += Get-ADGroupMember $group -Recursive |
`where {$_.objectclass -eq 'user'} |`
' select SamAccountName'
}

($gm.samaccountname | Select -Unique).Count
Write-Output total: ($gm.samaccountname | Select -Unique).Count

最佳答案

您可以通过更像Powershell的方式来执行此操作。

$groups  = $A_group, $B_Group
$uniqueMemberCount = $groups |
Get-ADGroupMember -Recursive |
Where-Object {$_.objectClass -ieq "user"} |
Select-Object -Unique |
Measure-Object |
Select-Object -ExpandProperty Count

Write-Output "Total: $uniqueMemberCount"

关于powershell - 计算Active Directory用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com