Getting ProxyAddresses from Get-ADuser in Powershell

This one for some reason always get’s me, and it always takes me longer than it should to find the answer… so if nothing else, this post is so I have quick access to the answer. To get the Proxyaddresses from the get-aduser cmdlet we can use the name and expression (or n= and  e=) pieces of Powershell. Proxy addresses cannot be pulled from Powershell directly as they are not a member of that command. The members of any command can be viewed by using the following:

get-aduser | get-member

Where get-aduser is replaced by your CmdLet. So, now that we know it is not a member of that command, how do we extract the proxyaddress information from powershell? …Use the -properties operator and the Name and Expression form to properly format the information.

This gets you the information:

get-aduser myuser -properties proxyaddresses

However, that doesn’t allow you to export that information… try the following:

get-aduser myuser -properties proxyaddresses | export-csv test.csv

This returns garbage where you’d hope your proxy addresses would be. To resolve this, pull the property, and then call it into your csv:

get-aduser myuser -properties * | select-object name, samaccountname, surname, enabled, @{"name"="proxyaddresses";"expression"={$_.proxyaddresses}} | Export-Csv test.csv

To be clear, following “name=” can be anything you want… it will be the header for the information you are calling. The “expression=” is calling the actual value. $_. is what is allowing you to access the value of “proxyaddresses” in the array.

Learning Powershell? This is a great book to help get you started.

Leave a Reply

%d bloggers like this: