A person can have a number of e mail addresses in Trade. Nevertheless, just one of them is his major e-mail handle. So what occurs if you wish to change one of many different addresses to your major e-mail handle?
A number of e mail addresses in Trade
All e mail addresses of a person are listed in Trade. The default response handle is displayed in daring on the next image:
Synchronisation of e mail addresses in AD
These addresses are additionally synchronised from Trade to your Energetic Listing. The worth within the attribute “mail” is the first handle. Additionally it is handy {that a} related view with all of the addresses as in Trade is accessible through the attribute “proxyAdresses”:
Change the first e mail handle in Trade
The Trade admin interface makes it simple to vary the first e mail handle. With Powershell it is a bit more sophisticated, but in addition attainable.
You will need to understand how Trade internally determines which e mail handle is the first one. Sadly, this isn’t as clear regulated as within the ActiveDirectory. Internally, Trade shops all e mail addresses within the identical attribute, along with a protocol prefix, that can be seen within the administration interface in Trade. Normally that is “smtp:”. The first e mail handle has a small however necessary distinction: The “SMTP:” in entrance of the handle is in capital letters.
So if we wish to set one of many proxy addresses as major, we have to capitalize the SMTP prefix of this one and lowercase the prefixes of all different addresses.
Distant entry to Trade with PowerShell
On this instance, we wish to entry the Trade remotely, i.e. we don’t wish to work immediately with the Trade Administration Console. For this, we’d like a PS session. We import the Trade session of the server through the URL, which consists as follows:
http: // <Title or IP of the server> / PowerShell
Import Get-Mailbox and Set-Mailbox
As well as, we won’t import the complete session however solely the CmdLets “Get-Mailbox” and “Set-Mailbox” , since we don’t want others. The session import appears like this:
$session = New-PSSession -ConfigurationName Microsoft.Trade -ConnectionUri “http://exc16/PowerShell” -Authentication Kerberos
Import-PSSession $session -CommandName Get-Mailbox, Set-Mailbox |
First we’d like an identifier for the person (his login identify, major e mail handle or objectGUID) whose mailbox we wish to edit. So we get hold of his mailbox:
$mb = Get-Mailbox steve.koenig |
Moreover we initialise an empty arraylist the place we’ll retailer our e mail addresses.
$listing = New-Object System.Collections.ArrayList |
Set a NewPrimaryMail
Then, we decide which mail handle needs to be the brand new major handle. This could already be assigned to the mailbox.
$newPrimaryMail = “koenig.steve@demofa.internet” |
Within the subsequent step we iterate over the e-mail addresses of the mail. Since these are entered with the prefix, we merely cut up them up on the colon and keep in mind each the prefix and the handle itself.
foreach($handle in $mb.EmailAddresses) { $prefix = $handle.Cut up(“:”)[0] $mail = $handle.Cut up(“:”)[1] } |
Now comes the step to the precise change of the first mail handle: We evaluate the handle with our $ newPrimaryMail. If they’re the identical, we add them to our listing with the capitalized prefix “SMTP:”. If not, then it’s one other handle we add to the listing with the already entered prefix, however in decrease case.
foreach($handle in $mb.EmailAddresses) { $prefix = $handle.Cut up(“:”)[0] $mail = $handle.Cut up(“:”)[1]
if ($mail.ToLower() -eq $newPrimaryMail.ToLower()) { $handle = “SMTP:” + $mail } else { $handle = $prefix.ToLower() + “:” + $mail }
$listing.Add($handle) } |
So our listing ought to now comprise our new major handle with a capital “SMTP” as prefix and the whole lot else with a lowercase prefix.
Switch listing to mailbox
Lastly we simply need to move the listing to the mailbox and overwrite the outdated one with it (and don’t forget to shut the PS session once more):
Set-Mailbox steve.koenig -EmailAddresses $listing Take away-PSSession $session |
The adjustments are instantly seen within the Trade Administration and can synchronise from Trade to AD afterwards.
The Full Script: Altering the Main Electronic mail Deal with with PowerShell
Lastly, right here is the complete script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$session = New-PSSession -ConfigurationName Microsoft.Trade -ConnectionUri “http://exc16/PowerShell” -Authentication Kerberos
Import-PSSession $session -CommandName Get-Mailbox, Set-Mailbox
$mb = Get-Mailbox steve.koenig $newPrimaryMail = “koenig.steve@demofa.internet” $listing = New-Object System.Collections.ArrayList
foreach($handle in $mb.EmailAddresses) { $prefix = $handle.Cut up(“:”)[0] $mail = $handle.Cut up(“:”)[1] if ($mail.ToLower() -eq $newPrimaryMail.ToLower()) { $handle = “SMTP:” + $mail } else { $handle = $prefix.ToLower() + “:” + $mail }
$listing.Add($handle) }
Set-Mailbox steve.koenig -EmailAddresses $listing
Take away-PSSession $session |
FirstAttribute AG – Microsoft Consulting Accomplice for Migration and Energetic Listing
We assist you with PowerShell scripting points.
Contact us
Did this aid you? Share it or depart a remark:
Article created: 03.11.2020