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.

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:

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

To set the user with a Proxy address:

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

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

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:

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

Remove multiple Proxy addresses from user:

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

All done!

Leave a Reply

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