Friday, November 8, 2024
HomePowershellChange major e mail handle with PowerShell

Change major e mail handle with PowerShell


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:

Multiple e-mail addresses in Exchange

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”:

27/5000 View the proxyAddresses

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:

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:

Moreover we initialise an empty arraylist the place we’ll retailer our e mail addresses.

Delegate Exchange tasks

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.

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.

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.

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):

The adjustments are instantly seen within the Trade Administration and can synchronise from Trade to AD afterwards.

New primary e-mail address in Exchange

 

The Full Script: Altering the Main Electronic mail Deal with with PowerShell

Lastly, right here is the complete script:

 


 

FirstAttribute AG

 
FirstAttribute AG – Microsoft Consulting Accomplice for Migration and Energetic Listing
We assist you with PowerShell scripting points.

Contact us
  

 

Article created: 03.11.2020

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments