检查属于组成员但不属于某个特定组的用户

时间:2016-03-30 08:56:10

标签: active-directory powershell-v2.0 user-management

我正在寻找一种方法来识别属于少数组(a,b,c)之一的用户,但也不在特定组(d)(一个例外组)中,以便稍后对它们执行某些任务(根据samaccountname的值填写特定属性)。

目前,我设法列出属于特定群组成员的用户帐户,并遵循将智能卡强制执行为假的其他条件:

$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}
}

然而,它并没有真正做到这一点,我确信这是一个更好的方法。

1 个答案:

答案 0 :(得分:0)

获取群组成员的专有名称列表" 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
    }
}
相关问题