2016-03-30 14 views
0

我正在尋找一種方法來識別屬於少數組(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} 
} 

定義例外的組然而,它並沒有真正做的伎倆,和我確定那裏有一個更好的辦法。

回答

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 
    } 
} 
+0

就像一個魅力!謝謝! – BoleslawA

+0

Ansgar,您是否碰巧遇到了某個挑戰,可以與我聊天?:)我可以以某種方式通過電子郵件或一些消息與您聯繫嗎? – BoleslawA

+0

聯繫信息可以在我的主頁上找到(鏈接位於我的[SO個人資料](https://stackoverflow.com/users/1630171?tab=profile))。 –

相關問題