Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created December 14, 2016 23:49
Show Gist options
  • Save chrisbrownie/fd0a1ead26ff5044fe4d2c6b61a10c08 to your computer and use it in GitHub Desktop.
Save chrisbrownie/fd0a1ead26ff5044fe4d2c6b61a10c08 to your computer and use it in GitHub Desktop.
Gets UPN, Mail, and primary SMTP address (from proxyAddresses)
# Show all
Get-ADUser -ldapFilter '(msExchMailboxGuid=*)' -Properties mail,UserPrincipalName,ProxyAddresses |
Select UserPrincipalName,mail,@{N="PrimarySmtpAddress";E={($_.proxyAddresses | Where {$_ -clike "SMTP:*"}).Split(":")[1]}}
# Show only where there is a mismatch
Get-ADUser -ldapFilter '(msExchMailboxGuid=*)' -Properties mail,UserPrincipalName,ProxyAddresses |
Select UserPrincipalName,mail,@{N="PrimarySmtpAddress";E={($_.proxyAddresses | Where {$_ -clike "SMTP:*"}).Split(":")[1]}} |
Where {
($_.mail.ToString() -ne $_.userPrincipalName.ToString()) -or
($_.mail.ToString() -ne $_.PrimarySmtpAddress.ToString()) -or
($_.UserPrincipalName.ToString() -ne $_.PrimarySmtpAddress.ToString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment