Export email aliases from users in Active Directory

ProxyAddresses in Active Directory is a multi valued attribute that contains all the e-mail aliases of a user. It can be a little tricky to spot or export.

In this PowerShell script we use some things you might not need like NoTypeInformation (which will remove #TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser) from the CSV file.

We also use -Encoding Unicode which will change the character encoding to UTF-16 format which we need for nordic letters in the user names.

$env:USERPROFILE\Desktop\ uses the relative path to the current users Desktop folder. $(get-date -f yyyy-MM-dd-HH-mm-ss) adds a time stamp to the filename for example 2022.01.29.

Remember to change ABCompany and the other variables to match your AD OU’s. Also I like to apply employeeID -like "*" so I can limit the search to users with employee numbers (human employees in other words) 😅

# Export users in Active Directory to text file or CSV

# Drilldown search a spesific OU folder
$searchScope = "OU=Users,OU=ABCompany,DC=abc,DC=local"

# Search with spesific filter
$searchFilter = {
    (employeeID -like "*") 
    -And (Enabled -eq $true) 

# Run the command
Get-ADUser -SearchBase $searchScope -Filter $searchFilter -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { $_.ProxyAddresses -join ";"}} | Export-Csv -Force -Path $env:USERPROFILE\Desktop\$(get-date -f yyyy-MM-dd-HH-mm-ss)-ProxyAddresses.csv -Encoding Unicode -NoTypeInformation

This will give you something like:

"john Smith","SMTP:jsmith@ABCompany.onmicrosoft.com;smtp:john@ABCompany.com;smtp:john@ABCompany.jp;smtp:john.smith@ABCompany.mail.onmicrosoft.com;SMTP:john.smith@ABCompany.fr;smtp:john.smith@ABCompany.com;smtp:john.smith@ABC.no

There are two downsides here.

We only get two CSV headers "Name" and "ProxyAddresses". We don’t get "ProxyAddresses" for each mail alias listed.

The other downside is that we also export the "x500:/o=ExchangeLabs/ou=Exchange Administrative Group" which is probably not needed. But I guess it is better to have too much information than too little.

I have not really found a solution for that yet…