Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/0ef60d8e847d460d02a15d1765d5ce8b to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/0ef60d8e847d460d02a15d1765d5ce8b to your computer and use it in GitHub Desktop.
$params = @{
SearchBase = (Get-ADDomain).DistinguishedName
Filter = { proxyAddresses -like '*' }
Properties = 'Displayname',
'SamAccountName',
'UserPrincipalName',
'ProxyAddresses',
'DistinguishedName'
}
Get-ADUser @params |
Select-Object DisplayName, SamAccountName, UserPrincipalName,
@{n="OU"; e={ $_.DistinguishedName -replace 'CN=[^=]+,' }},
@{n="PrimarySMTP"; e={
$upn = $_.UserPrincipalName
($_.proxyAddresses | Where-Object { $_ -clike 'SMTP:*' -and $_ -ne $upn }) -join ', ' }} |
Export-Csv .\primarySMTPnotMatchUPN.csv -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment