Recently I have been assigned a task to populate/change AD users attribute called ProxyAddresses. Generally, that’s not so hard – a few clicks and a bit of writing. But this time, it had to be done for a couple of hundreds of users. It was time to spend some time and create a PowerShell script that will make my day easier.

So, here is the first part.

#Part I
#Be sure to change example DC path with yours
$OU = Read-Host 'What is the name of the OU?'
$path = "OU=$OU,DC=tech-trainer,DC=info"

Get-ADUser -SearchBase $path -Properties proxyaddresses -Filter * |
    select-object name, samaccountname, surname, enabled, @{"name"="proxyaddresses";"expression"={$_.proxyaddresses}} | 
        Export-Csv c:\users.csv

Here we will read all users from one OU and export them with needed data to a CSV file.

Now comes the hard part – you do need to edit data in CSV so it complies with the new request. I’m guessing that you do know how to use search/replace and will not bother you with that 🙂

After a successful edit, we may return our file to the server and execute the second part.

#Part II
$Userscsv = Import-Csv C:\users_proxy.csv
ForEach ($User in $Userscsv)
    #We need to clear existing addresses from the list
    Set-ADUser $User.samaccountname -Clear proxyAddresses

    #This line reads addresses from our edited csv file
    $proxyAddresseslist = $User.proxyaddresses

    #My file was exported with space beetwen addresses and that's way split is by space
    foreach( $ProxyAddress in ( $proxyAddresseslist -split ' ' ) ){
    Set-ADUser $User.samaccountname -Add @{proxyaddresses = $proxyAddress}

After a few seconds, all of your users ProxyAddresses attribute will be changed.

Be sure to change needed OU paths and file names if you like.

Have another great day in Admins life 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.