Tatankasa
asked on
Exchange 2013 Powershell script to manually add new email addresses for new domain based on old ones
Hey all! So my Google powers have let me down today. I'm preparing to add a new domain to our Exchange server, and I need to ensure that all email addresses that exist for our old domain are duplicated with the new domain for all our mailboxes. I believe I could do this fairly well using email address policy (just a simple all users get <alias>@<newdomain>) but I know that a lot of our mailboxes have one or two aliases on the old domain, and a bunch of them are set to not follow the policy anyways.
So, what I'm hoping to find/build is a script that crawls through each mailbox in turn, pulls all the email addresses, and for each address that exists on the old domain, create an additional one on the new domain. The other hitch is that we have two other domains, each used by a handful of mailboxes, that are not to be affected by this, so it would not be enough to simply duplicate every address, it would have to check each address to ensure it was @<olddomin>, and not @<otherdomain1> or @<otherdomain2>.
I'll also have to do something similar with setting the default reply address for each mailbox. Read the default smtp reply address and if it's @<olddomain>, set the @<newdomain> address as the default smtp reply.
Anyone know of such a script? Or possibly you are such a powershell master you could whip it up with little effort? I can probably do a lot of it myself if I have something to work from, but I'm not so good with a lot of the specific syntax related to pulling attributes like email addresses and parsing them for comparisons. Any assistance would be appreciated, thanks!
So, what I'm hoping to find/build is a script that crawls through each mailbox in turn, pulls all the email addresses, and for each address that exists on the old domain, create an additional one on the new domain. The other hitch is that we have two other domains, each used by a handful of mailboxes, that are not to be affected by this, so it would not be enough to simply duplicate every address, it would have to check each address to ensure it was @<olddomin>, and not @<otherdomain1> or @<otherdomain2>.
I'll also have to do something similar with setting the default reply address for each mailbox. Read the default smtp reply address and if it's @<olddomain>, set the @<newdomain> address as the default smtp reply.
Anyone know of such a script? Or possibly you are such a powershell master you could whip it up with little effort? I can probably do a lot of it myself if I have something to work from, but I'm not so good with a lot of the specific syntax related to pulling attributes like email addresses and parsing them for comparisons. Any assistance would be appreciated, thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you are most welcome, glad was able to help
thanks for the updated version too :D
thanks for the updated version too :D
ASKER
[code]$mbxs = Get-Mailbox -ResultSize unlimited
$olddomain = "<olddomain>"
$newdomain = "<newdomain>"
foreach ($mbx in $mbxs){
$SMTPAddresses = $mbx.EmailAddresses | where {$_.Split(":")[0] -eq "SMTP"}
foreach($SMTPAddress in $SMTPAddresses){
$Addressdomain = $SMTPAddress.Split("@")[1]
$AddressAlias = $SMTPAddress.Split("@")[0]
Write-Host ""
Write-Host $AddressAlias " " $Addressdomain
if($Addressdomain -eq $olddomain){
if($SMTPAddress.Split(":")
$AddressAlias = "smtp:" + $AddressAlias.Split(":")[1
$NewSMTPAddress = "$AddressAlias@$newdomain"
Write-Host "Yes old domain so new address:" $NewSMTPAddress
#Set-Mailbox $mbx.Alias -EmailAddresses @{add=$NewSMTPAddress}
if(!($mbx.EmailAddressPoli
Write-Host "Policy not enabled, so manually make primary"
#Set-Mailbox $mbx.Alias -PrimarySmtpAddress ($NewSMTPAddress.Split(":"
}
}
else {
$NewSMTPAddress = "$AddressAlias@$newdomain"
Write-Host "Yes old domain so new address:" $NewSMTPAddress
#Set-Mailbox $mbx.Alias -EmailAddresses @{add=$NewSMTPAddress}
}
}
else {
Write-Host "Not old domain, so no new address"
}
}
}
[/code]