活动目录从GroupA中删除用户,如果GroupB的成员

在Active Directory中,如何有效地删除GroupA中所有属于GroupB成员的用户? 基本上我想从A中减去B.

现在有:

AAA BBB --- --- Alice Alice Charlene Bruce Chuck Chuck 

期望:

 AAA BBB --- --- Alice Charlene Bruce Chuck 

我目前在csv中有用户列表,但如果需要,可以快速重为其他内容:

 logon, group alice, AAA alice, BBB bruce, BBB ... 

我不是ADpipe理员,只是具有这些组的写入权限的用户。

Powershell Active Directory Web服务。 所有的域控制器2008 R2或更好默认情况下。

 # This foreach loop enumerates through all members of the AAA group. Foreach ($Usr In Get-ADGroupMember -Identity 'CN=AAA,CN=Users,DC=Contoso,DC=com') { # If the 'MemberOf' array of $Usr's group memberships contains 'BBB', then... If ((Get-ADUser $Usr.SamAccountName -Properties MemberOf).MemberOf -Contains 'CN=BBB,CN=Users,DC=contoso,DC=com') { # Remove that user from 'AAA'. Remove-ADGroupMember -Identity 'AAA' -Members $Usr.SamAccountName } } 

这将删除“BBB”组中的所有“AAA”组成员。 不需要CSV。

如果使用的不是Powershell 3,请在开始使用AD cmdlet之前使用Import-Module ActiveDirectory