This script uses the Active Directory PowerShell module to locate duplicate proxyaddresses throughout your forest. The script must be run from a computer that have the AD PowerShell installed, and can reach all PDCEmulators in all domains in your forest.
Import-Module ActiveDirectory # Create hashmap for proxyaddresses $proxyaddresses = @{} # For each domain in the forest Get-ADForest | Select-Object -ExpandProperty Domains | Get-ADDomain | foreach { Write-Output ("Parsing domain {0} by contacting {1}" -f $_.Name, $_.PDCEmulator) # Get all AD objects that have proxyaddresses Get-ADObject -Filter {proxyaddresses -like "*"} -Properties proxyaddresses -Server $_.PDCEmulator | foreach { $_.proxyAddresses | foreach { $proxyaddresses[$_] += 1} } } Write-Output "Done, looking for duplicates" $duplicates = $proxyaddresses.Keys | where{$proxyaddresses[$_] -gt 1} # Output proxyaddresses that are duplicates if($duplicates) { Write-Output "The following proxyaddresses was found multiple times" $duplicates # | Out-Gridview # Remove first hash-sign in order to get an "Excel"-view. Needs PowerShell ISE. } else { Write-Output "No duplicates found" }
Reblogged this on My Tech Junk Yard.
Well done! I like the approach. Thanks!
Is there anyway I can email it to myself if/when duplicates found?
Yes, by using the Send-MailMessage cmdlet and running the script as a scheduled task this is fairly straight forward.
How do I then tell it to delete the duplicate addresses?
Hi Wendy, it all depends on the amount of users. This blog post is very old, and I would recommend that you have a look at the Idfix tool from Microsoft: https://docs.microsoft.com/en-us/office365/enterprise/install-and-run-idfix
This is essentially made to aid you prepare your AD for sync to Azure AD / Office 365, but it works for this purpose aswell 🙂