Get-ADUser -Filter * |
Group-Object SamAccountName -NoElement |
Where-Object Count -gt 1 |
Export-Csv DuplicateSamAccountName.csv -NoTypeInformation
If it's multiples of 1000 it's likely to need something a little more refined than that.Get-ADUser -Filter * -Properties Description |
Group-Object Description -NoElement |
Where-Object Count -gt 1 |
Export-Csv DuplicateDescription.csv -NoTypeInformation
Queries like this, where the majority of the heavy lifting is client-side, are best run from a workstation with the RSAT package installed (specifically the AD PowerShell tools). The AD, of course, will still be taking get of the LDAP query (behind the scenes).Get-ADUser -Filter * |
Group-Object SamAccountName -NoElement |
Sort-Object Name |
Export-Csv DuplicateSamAccountName.csv -NoTypeInformation
Chris
$CSVfile = "$($env:onedrivecommercial)\output\DuplicateSAM.csv"
$users = @()
ForEach ($domain in (get-adforest).domains) {
$DomObj = Get-ADDomain $domain
"Querying users in $($DomObj.Name)"
$users += Get-ADUser -filter * -SearchBase $DomObj.DistinguishedName -Server $DomObj.RIDMaster
}
write-host "Read $($users.count) users. Looking for duplicates..."
$dupes = $users | Group-Object SamAccountName | Where-Object Count -gt 1
write-host "Duplicates found: $($dupes.count)"
$dupes | Export-Csv -Path $CSVfile -NoTypeInformation