Exchange Email Domain Change Script

So I had a client that was going through a rebranding. No big deal normally but they have many different email domain names for their lines of business and also do not use the email address policies since their naming rules are too complex.
Normally I would just write a quick script that takes the old domain and swaps it out with the new domain but since multiple domains would need to be changed I'd have to have a script for each one. Instead what I did is write a simple script that takes command line arguments to specify the old and new domains.

This worked great! But then the client wanted to see what is going to happen before the changes were made, so I added a -makechanges switch to distinguish between reporting and making changes.

After that the client wanted to send each of the users an email notifying them of the changes with an email (html formatted of course). So I added a mailing function to the script that takes an HTML template file and replaces the user specific info before sending so that each user gets a nice, pretty, personalized email notification.

Things were going well up until this point when the client wanted to change the distribution list email addresses domains also, but they didn't want to send an email to them. OK, I can do that, I just changed the script to use a type variable that if set to 1 (for MBs) will send an email notification, and if set to 2 (for DLs) would not.

After I finished up I thought: "I bet someone else might have to do something similar to this so I should post this on out blog....."

Well here's the script. Remember that this can be used as a starting point for your needs too, there are some specific issues that I had to use which may not work for you (like using the displayname instead of given and surname fields). Take a look at the script code, I've commented the code liberally, and make changes where you need to.

https://github.com/mikecessna/Replace-EmailAddressDomain/blob/master/Replace-EmailAddressDomain.ps1

Labels: ,