AntiMalware Status

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.

1
2
3
4
5
6
7
Import-module ActiveDirectory
Import-Csv .\SMTPLIST.csv | ForEach-Object
{
$username = $_.samaccountname
$userproxy = $_.emailaddress -split ';'
Set-ADUser -Identity $username -Add @{proxyAddresses= $userproxy}
}

To see proxy address for the user:

1
Get-ADUser john.doe -Properties ProxyAddresses | select Name, ProxyAddresses

To set the user with a Proxy address:

1
Set-ADUser John.Doe -add @{ProxyAddresses="smtp:john.doe@domain.com"}

Also you can add multiple Proxy address in PowerShell command line:

1
Set-ADUser John.Doe -add @{ProxyAddresses="smtp:john.doe@onmicrosoft.com,SMTP:john.doe@domain.com" -split ","}

In case you wish remove the proxy address from user:

1
Set-ADUser John.Doe -remove @{ProxyAddresses="SMTP:john.doe@domain.com"}

Remove multiple Proxy addresses from user:

1
Set-ADUser John.Doe -remove @{ProxyAddresses="smtp:john.doe@onmicrosoft.com,SMTP:john.doe@domain.com" -split ","}

All done!

Leave a Reply