Get-AdUser cmdlet in PowerShell has proxyAddresses attribute which contains collections of proxy addresses.
In this article, we will discuss how to get aduser proxyaddresses using PowerShell script and get aduser proxyaddresses filter by SMTP and export to CSV file.
Get AdUser ProxyAddresses
Get-AdUser proxyaddresses attribute gets aduser all proxyaddresses values.
As proxyaddresses contains a collection of strings, we will use a like or match comparison operator to find SMTP type address and join address by delimiter as given below
Get-ADUser -Filter * -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like 'smtp:*') -join ";"}} | Export-Csv -Path C:\PowerShell\AdUsersProxyAddresses.csv -NoTypeInformation
In the above PowerShell script,
Get-AdUser Filter parameter with * (wildcard) to get all aduser proxyaddresses and passes the output through pipeline operator to the second command.
The second command uses Select-Object to get aduser proxyaddresses where proxyaddress begins with smtp
The above command gets all proxyaddresses for the active directory user and using Export-Csv cmdlet, it exports aduser proxyaddresses to the CSV file.
You can also use match comparison operator to get aduser all proxyaddresses which begins with smtp as given below
Get-ADUser -Filter * -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -match '^smtp:') -join ";"}}
In the above PowerShell script,
GetAduser gets all aduser proxyaddresses and using match comparison operator, it filters proxyaddresses which starts with smtp.
It later joins proxyaddress by delimiter; and prints aduser name and proxyaddress on the terminal.
Get AdUser All ProxyAddresses
You can also get aduser proxyaddress identified by samaccountname as given below
Get-ADUser -Identity Arons -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like 'smtp:*') -join ";"}}
In the above PowerShell script,
Get-AdUser cmdlet gets proxyaddresses for aduser Arons. Proxyaddresses are joined by; delimiter
The output of the above command as below
PowerShell Tip: How to get aduser parent OU container in PowerShell!
Conclusion
I hope the above article on how to get aduser proxyaddresses is helpful to you.
Get-AdUser proxyaddresses attribute is used to get aduser all proxyaddresses of type sip or smtp.
Using Export-Csv cmdlet in PowerShell, you can get aduser proxyaddresses export to CSV file.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.
For those with a large number of AD Objects, it’s worth noting that you can also use the built-in “-filter” argument on the ProxyAddresses attribute (and any other array-type attributes).
For example, I used the following command to make sure that I didn’t have any ‘plus addresses’ assigned to any objects before we enabled that feature in our Email tenant:
Get-ADUser -Filter {ProxyAddresses -like “*+*”}
I also use this same tactic to locate and resolve duplicate proxy addresses.