如何在Active Directory中查找重复项

时间:2016-02-16 07:18:24

标签: powershell foreach active-directory

我试图通过自定义属性employeeId

在AD(windows 2008 r2)中找到重复的对象
Get-ADUser -Filter {(employeeID -like "*")} 
| Select-Object Enabled, ObjectClass, Name, UserPrincipalName, SamAccountName, employeeID 
| 
    ForEach-Object {  
        $obj1 = $_
        ForEach-Object { 
            if($_.employeeID -eq $obj1.employeeID){

            }
        }
    }
| Export-Csv C:\Users\user\Desktop\mployeeId_is_duplicate.csv

感谢

1 个答案:

答案 0 :(得分:2)

尝试使用group-object并选择所有具有Count>的实体2像这样:

Get-ADUser -Filter {(employeeID -like "*")} -property employeeID |Group
employeeid | ? {$_.Count -ge 2} | select -ExpandProperty group | Select-
Object Enabled, ObjectClass, Name, UserPrincipalName, SamAccountName, 
employeeID | Export-Csv C:\Users\user\Desktop\mployeeId_is_duplicate.csv