Merge a MailContact with a User
Often when doing migrations some form of GalSync has taken place or where admins have manually created mailcontacts in the opposite Exchange Org to assist with coexistence. However when it comes time to do the migration the Prepare-MoveRequest.ps1 it will convert the MailContact into a MailUser and ensure it has the mailboxGUID and other attributes to allow a New-MoveRequest to succeed.
However often there are users who, as well as having a MailContact, also have a standard user object to allow them to access applications in the remote forest. Now I know that trusts can be added, etc, etc. I am not debating the rights and wrongs of how the users got into that state (that would be an interesting blog too though…)
The question is how can you merge the contact and the user together, since you don’t just want to delete either one. You could but you’d either lose permissions granted to the user object, or you’d lose replyability for the contact.
Fear not though, since attached here you will find a script that given a Contacts identity it will find a user that matches on PrimarySMTPAddress (or alternatively ExternalEmailAddress). Once it has found a matching user then it will save the info from the Contact, remove the Contact, mail enable the user and stamp the relevant attributes from the contact onto the user.
Now Merge isn’t a valid PowerShell verb so I chose to use Join instead which seems the closest I could see. If you need more attributes copied from the MailContact to the now MailUser then the script can be easily edited to accommodate. You can just add more lines below
$parameters.add( 'ExtensionCustomAttribute5', $MailContact.ExtensionCustomAttribute5 )
*** As always the script is provided on an as is basis, please test it before you use it in a production environment. ***