【发布时间】:2015-11-03 19:08:50
【问题描述】:
我们的环境中有两个组 'contractors' 和 'employees' ,我需要编写一个脚本来列出不属于这两个组的所有用户,有人可以帮助我吗?
$n = Get-ADGroupMember "Contractor" | Sort-Object |
foreach {Get-ADUser $_.name | select name}
$group = "Employee"
foreach ($u in $n) {
$get = (Get-ADUser $u.Name -Properties * | Select-Object memberof)
if ($get.memberof -match $group) {
Write-Host $u.name " is ok. They're in both groups."
} else {
Write-Host $u.Name " is not a member" -ForegroundColor Red -BackgroundColor Yellow
}
}
【问题讨论】:
-
当然。向我们展示您目前拥有的代码并解释您遇到的具体问题,我们将帮助您从那里改进。
-
我没有得到正确的输出,附上我试过的脚本
-
请编辑您的问题。如您所见,代码在注释中往往变得不可读。如果您没有得到正确的输出,您还需要提供示例输入以及实际和期望的输出。
-
您在运行此代码时是否遇到任何错误?如果是链接发布错误代码
-
我得到的错误是我正在获取属于任一组(承包商或员工)的用户列表,我需要不属于这两个组的用户的输出
标签: powershell