Add SMTP-ProxyAddress to users in AD with PowerShell

Here is a quick way to add new SMTP/ProxyAddress for the users in Active Directory with use of PowerShell.

Create a csv file with two columns
samaccountname | emailaddress
john.doe                 | smtp:john.doe@testdomain.com

First column has user samaccountname and second column make sure you use the format; “smtp:samaccountname@domain.com

Once you have the csv file ready you can run this PowerShell script to update all those users with new SMTP/ProxyAddress.

[cc lang=”PowerShell”]
Import-module ActiveDirectory
Import-Csv .\SMTPLIST.csv | ForEach-Object
{
$username = $_.samaccountname
$userproxy = $_.emailaddress -split ‘;’
Set-ADUser -Identity $username -Add @{proxyAddresses= $userproxy}
}
[/cc]

To see proxy address for the user:
[cc lang=”PowerShell”]
Get-ADUser john.doe -Properties ProxyAddresses | select Name, ProxyAddresses
[/cc]
To set the user with a Proxy address:
[cc lang=”PowerShell”]
Set-ADUser John.Doe -add @{ProxyAddresses=”smtp:john.doe@domain.com”}
[/cc]
Also you can add multiple Proxy address in PowerShell command line:
[cc lang=”PowerShell”]
Set-ADUser John.Doe -add @{ProxyAddresses=”smtp:john.doe@onmicrosoft.com,SMTP:john.doe@domain.com” -split “,”}
[/cc]
In case you wish remove the proxy address from user:
[cc lang=”PowerShell”]
Set-ADUser John.Doe -remove @{ProxyAddresses=”SMTP:john.doe@domain.com”}
[/cc]
Remove multiple Proxy addresses from user:
[cc lang=”PowerShell”]
Set-ADUser John.Doe -remove @{ProxyAddresses=”smtp:john.doe@onmicrosoft.com,SMTP:john.doe@domain.com” -split “,”}
[/cc]

All done!

Leave a Reply