Find duplicate mail addresses
Documentation: Microsoft Learn
Every user is retrieved with the mail attribute, accounts holding no address are dropped, Group-Object buckets the remainder by address, and only buckets with more than one member survive.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-ADUser -Filter * -Properties mail | Where-Object mail | Group-Object mail | Where-Object Count -gt 1 | Select-Object Name,Count- Stage 1Get-ADUser
-Filter -Properties - Stage 2Where-Object
Positional values or no named parameters - Stage 3Group-Object
Positional values or no named parameters - Stage 4Where-Object
-gt - Stage 5Select-Object
Positional values or no named parameters
How it works
Every user is retrieved with the mail attribute, accounts holding no address are dropped, Group-Object buckets the remainder by address, and only buckets with more than one member survive. In the output, Name is the offending address and Count is how many accounts claim it.
Adapting it
Request proxyAddresses instead and group on the expanded values, because in a hybrid directory the collisions that actually break synchronization usually live there rather than in the primary mail attribute.
Requirements
ActiveDirectory module.
If the result is unexpected
The duplicate-mail report groups accounts that should not share an address, or misses an alias conflict.
Grouping the mail attribute does not inspect every proxy address and blank values can form a misleading group.
- Exclude empty mail values and inspect each group before comparing aliases in the appropriate attribute.
Validate the result
Each reported group contains at least two distinct account identities sharing the compared value.
Keep the check reliable
Document whether the audit covers primary mail values, aliases or both.