Configure Proxy addresses (SMTP) to all the users in OU using SAM Account and a Public Domain on Active Directory

 

This PowerShell will look up at your active directory user’s Proxy Addresses attribute and see if it’s empty, it’ll change it to include a Primary SMTP Address using user’s SamAccount + domain you configure in the PowerShell.

 

image

## READY

 

Import-Module ActiveDirectory

 

Write-host “If the user’s proxy attribute is empty the powershell will add user proxy address..” -ForegroundColor yellow

 

$proxydomain = “@PublicDomain.com” #Specify the domain you’d like to add as user’s primary SMTP Address.

$userou = “OU=Test,DC=moh10ly,DC=com” #Specify the OU where you want the PowerShell to work in your AD

$users = Get-ADUser -Filter { ProxyAddresses -notlike “*” } -SearchBase $userou -Properties SamAccountName, ProxyAddresses, givenName, Surname

 

Foreach ($user in $users) {

write-host $user.DistinguishedName

Set-ADUser -Identity $user.SamAccountName -Add @{Proxyaddresses=“SMTP:”+$($user.samaccountname)$($proxydomain)}

#

write-host “ProxyAddress is Set” -ForegroundColor Green -BackgroundColor Black

}

 

 

 

### for Mail Attribute ###

 

## READY

Import-Module ActiveDirectory

$proxydomain = “@Publicdomain.com”

$userou = “OU=Test,DC=moh10ly,DC=com”

Write-host “Set user’s mail attribute to $proxydomain -ForegroundColor White

$users = Get-ADUser -Filter * -SearchBase $userou -Properties SamAccountName, ProxyAddresses, givenName, Surname, mail

Foreach ($user in $users) {

 

    write-host $user.mail

 

    Set-ADUser -Identity $user.SamAccountName -Replace @{mail=$($user.samaccountname)$($proxydomain)}

 

    #

 

    write-host “ProxyAddress is Set” -ForegroundColor Green -BackgroundColor Black

 

    }