
[英]Checking Someone is a Member Of One of Many Groups Using Partial Group Name
[英]Checking for users who are member in on of groups, but not in one specific group
我正在寻找一种方法来识别属于少数几个组(a,b,c)之一但又不在特定组(d)(例外组)中的用户,以便稍后对他们执行一些任务(填写基于samaccountname的值的特定属性)。
现在,我设法列出了属于特定组的用户帐户,并遵循将智能卡强制实施为false的另一种条件:
$groups = "a","b","c"
foreach ($group in $groups) {
Get-ADGroupMember -Identity $group |
Get-ADUser -Properties 'smartcardlogonrequired' |
where {$_.smartcardlogonrequired -eq $false}
}
我想到了。 通过以下方式定义例外组
$exceptions = (Get-ADGroup 'd').distinguishedname
foreach ($group in $groups) {
Get-ADGroupMember -Identity $group |
Get-ADUser -Properties 'smartcardlogonrequired' |
where {$_.smartcardlogonrequired -eq $false} |
Get-ADUser –Filter {-not(memberof –eq $d}
}
但是,它并不能真正解决问题,而且我相信还有更好的方法。
获取“ d”组成员的可分辨名称的列表,并过滤可分辨名称不属于该列表的用户:
$exceptions = Get-ADGroupMember 'd' | Select-Object -Expand DistinguishedName
foreach ($group in $groups) {
Get-ADGroupMember -Identity $group |
Get-ADUser -Properties 'smartcardlogonrequired' |
Where-Object {
$_.smartcardlogonrequired -eq $false -and
$exceptions -notcontains $_.DistinguishedName
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.