Author Posts

August 11, 2017 at 8:24 am

Hello everyone,

I have such a complex task to acomplish(probably complex for me), basically we have one forest/domain that is syncing with O365.
Primary SMTP address is not leading any specific format, for example first+lastname , for some users it is last+firstname
We have to get all of the user SMTP addreses, that can be done easy; get-aduser -filter * -property * | where {$_.ProxyAddresses -clike "SMTP*@domain.name"}

Question is, how we can preserve everything before @domain.name , so the user first+last or last+first name don't change, and change only domain name.

Help will be greatly appreciated !

Kind regards,
Nemanja

August 11, 2017 at 8:53 am

Just to clarify a few things.
1) Do you want the existing SMTP address preserved as a secondary address?
2) The new SMTP address you want to be the same as the old one just with a new domain name?

August 11, 2017 at 9:24 am

Hi,

We don't want to add secondary SMTP address, we want to change the primary one, as you said, just to change domain while preserving everything behind @domain.name

Kind regards,
N

August 11, 2017 at 9:44 am

ok assuming you know how to get the users current smtp address to get the bit before the @ sysmbol you could use

$local = $SMTP.local # Where $SMTP is the users SMTP Address

with this you could create the new SMTP address
$NewSMTP = $Local + "@" + $newdomainname

Then using set-mailbox you will be able to set the new primary SMTP address

August 11, 2017 at 10:42 am

This looks excellent, but I am still struggling to complete it, since I am not still really good with parsing informations, advise please if you have some tips 🙂

So I did this for my user for example;

$nemanja = Get-ADUser -Filter * -Properties * | Where-Object {$_.Name -like "nemanja.jovic"}

After I call;

$nemanja.proxyaddresses

But it is coming with multiple SMTP and smtp addresses, how I can parse from here just SMTP for further script process?

Thanks,
N

August 11, 2017 at 11:10 am

try this

Get-ADUser -Identity -Properties ProxyAddresses | Where-Object {$_.ProxyAddresses -cmatch "SMTP"}

This should only bring back the primary address as it is case sensitive and onlt the primary will have SMTP in caps

August 15, 2017 at 11:44 am

This is how I managed to complete this task;

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Get-ADUser -SearchBase "OU=TEST,DC=DOMAIN,DC=GLOBAL" -Filter * -Properties * | Where-object {$_.ProxyAddresses -clike "SMTP:*@domain.global"} | Select-Object UserPrincipalName,SamAccountName | Export-Csv -Path C:\users.csv
$userobjects = Import-Csv -Path C:\users.csv
foreach ($user in $userobjects){
$newdomain = "test.domain"
$address = ((Get-Mailbox -Identity $user.UserPrincipalName).Primarysmtpaddress).toString()
$Alias=$Address.Split("@")[0]
$newsmtp="$alias@$newdomain"
Set-ADUser -Identity $user.SamAccountName -Add @{proxyAddresses="SMTP:"+$newsmtp}
Set-ADUser -Identity $user.SamAccountName -Remove @{proxyAddresses="SMTP:"+$address}
}