Skip to content

Instantly share code, notes, and snippets.

@kevinblumenfeld
Created September 12, 2017 02:06
Show Gist options
  • Save kevinblumenfeld/cb4a48e9d634847c7b734587aee37735 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/cb4a48e9d634847c7b734587aee37735 to your computer and use it in GitHub Desktop.
Get-ADUser -Filter 'proxyaddresses -ne "$null"' -ResultSetSize $null -Properties DisplayName, samaccountname, UserPrincipalName, proxyAddresses, Distinguishedname -searchBase "DC=CONTOSO,DC=local" |
select DisplayName, samaccountname, UserPrincipalName,
@{n = "OU" ; e = {$_.Distinguishedname | ForEach-Object {($_ -split '(OU=)',2)[1,2] -join ''}}},
@{n = "PrimarySMTP" ; e = {( $_.proxyAddresses | ? {$_ -cmatch "SMTP:*"}).Substring(5) -join ";" }},
@{n = "smtp" ; e = {( $_.proxyAddresses | ? {$_ -cmatch "smtp:*"}).Substring(5) -join ";" }},
@{n = "x500" ; e = {( $_.proxyAddresses | ? {$_ -match "x500:*"}).Substring(0) -join ";" }},
@{n = "SIP" ; e = {( $_.proxyAddresses | ? {$_ -match "SIP:*"}).Substring(4) -join ";" }} |
Export-Csv ADUsers.csv -NTI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment