Converting a Mailbox to a MailUser (and preserving your custom attributes)

It’s not often that you’ll need to convert a mailbox to a mail-user, but when you do, you’ll soon realize the steps go like this:

1. Mail-Disable the user (delete the mailbox)
2. Mail-Enable the user

So what’s the problem?  The problem is twofold:

  • First, you’ll want to automate this, and there is no “convert” button or command.  You’ll need to use PowerShell if converting multiple users.
  • Second, and perhaps more importantly, all the Exchange attributes are nullified when you delete the mailbox.  This includes CustomAttribute1-15

As we can see, you are not able to pass mailboxes to the Enable-MailUser (as you are able to do in reverse):

I’ve written a script to solve these problems.  Before you run with it, you do need to make one decision:

What do you want the mail-user’s external email address to be?

The below script takes the user’s mailbox alias and then appends  You may wish to modify this with whatever their new external address has become.

You’ll also notice I’m using a static domain controller for all configurations.  I have found in my testing, that if you do not pick the same DC for all operations, the script could out-run replication.

$DomainController = (Get-ADServerSettings).DefaultConfigurationDomainController.domain

$MailboxList= Get-Mailbox

foreach ($Mailbox in $MailboxList) {
    Disable-Mailbox -Id $mailbox.Identity -Confirm:$False -DomainController $DomainController
    Enable-MailUser -Id $mailbox.Identity -ExternalEmailAddress ($mailbox.alias +"") -DomainController $DomainController
    Set-MailUser -Id $mailbox.Identity `
     -DomainController $DomainController `
     -CustomAttribute1 $Mailbox.CustomAttribute1 `
     –CustomAttribute2 $Mailbox.CustomAttribute2 `
     –CustomAttribute3 $Mailbox.CustomAttribute3 `
     –CustomAttribute4 $Mailbox.CustomAttribute4 `
     –CustomAttribute5 $Mailbox.CustomAttribute5 `
     –CustomAttribute6 $Mailbox.CustomAttribute6 `
     –CustomAttribute7 $Mailbox.CustomAttribute7 `
     –CustomAttribute8 $Mailbox.CustomAttribute8 `
     –CustomAttribute9 $Mailbox.CustomAttribute9 `
     –CustomAttribute10 $Mailbox.CustomAttribute10 `
     –CustomAttribute11 $Mailbox.CustomAttribute11 `
     –CustomAttribute12 $Mailbox.CustomAttribute12 `
     –CustomAttribute13 $Mailbox.CustomAttribute13 `
     –CustomAttribute14 $Mailbox.CustomAttribute14 `
     –CustomAttribute15 $Mailbox.CustomAttribute15

(add more attributes if necessary, but remember that since you aren’t deleting the Active Directory object itself, most attributes remain…)

14 thoughts on “Converting a Mailbox to a MailUser (and preserving your custom attributes)

  1. Hi Mike,

    Very useful! Great post.

    It might be a good addition to pull out the LegacyExchangeDN also before disabling too, then checking the new LegacyExchangeDN and if different adding it as an X500 address.

    I know by specifying the DC you can avoid some of the issues associated with this but not all; such as if there had been enables/disables of the mailbox in the past resulting in numbers at the end.


  2. I have a CSV file with external email address. Let me know how can I pull email address from the CSV instead using $mailbox.alias+domain name. Thanks

  3. Hi Mike,

    i found your site and thougth you already did the x500 thing. If the LegacyExchangeDN changes and we dont copy it to a X500 address, then the users will get a delivery error on picking the old users from the nick cache.

    Because it wasnt there i added it quick to your script, hope it helps someone:

    $ExchangeServer = (get-pssession).ComputerName
    $DC = (Get-ExchangeServer $ExchangeServer -status).CurrentConfigDomainController

    $MailboxList = Get-Mailbox

    foreach ($Mailbox in $MailboxList)

    $LegacyExchangeDN = $mailbox.LegacyExchangeDN

    Disable-Mailbox -ID $mailbox.Identity -Confirm:$False -DomainController $DC;

    Start-Sleep -s 2

    $mu = Enable-MailUser -Id $mailbox.Identity -ExternalEmailAddress ($mailbox.alias + “”) -DomainController $DC;

    Start-Sleep -s 2

    Set-MailUser -Id $mailbox.Identity -DomainController $DC -CustomAttribute1 $Mailbox.CustomAttribute1 –CustomAttribute2 $Mailbox.CustomAttribute2 –CustomAttribute3 $Mailbox.CustomAttribute3 –CustomAttribute4 $Mailbox.CustomAttribute4 –CustomAttribute5 $Mailbox.CustomAttribute5 –CustomAttribute6 $Mailbox.CustomAttribute6 –CustomAttribute7 $Mailbox.CustomAttribute7 –CustomAttribute8 $Mailbox.CustomAttribute8 –CustomAttribute8 $Mailbox.CustomAttribute8 –CustomAttribute9 $Mailbox.CustomAttribute9 –CustomAttribute10 $Mailbox.CustomAttribute10 –CustomAttribute11 $Mailbox.CustomAttribute11 –CustomAttribute12 $Mailbox.CustomAttribute12 –CustomAttribute13 $Mailbox.CustomAttribute13 –CustomAttribute14 $Mailbox.CustomAttribute14 –CustomAttribute15 $Mailbox.CustomAttribute15

    if ($LegacyExchangeDN -ne $mu.LegacyExchangeDN)
    $X500 = “X500:” + $LegacyExchangeDN
    Set-MailUser $mu -EmailAddresses (($mu.EmailAddresses)+=$X500) -DomainController $DC


  4. Hi Mike,

    Need your help in writing a script for single users’ mailbox conversion into mail enabled contacts. Kindly help me in writing this script as i am completely stuck with migration.

    Do reply as soon as possible.



    • Mailboxes and Mail-Users are both Active Directory “User” objects. Mail-Contacts are Active Directory “Contact” objects, therefore the conversion will must destroy the user account and replace it with a contact, losing all attributes, group memberships, etc. You need to identify the attributes you want to preserve, and hold them in a variable during the conversion. For example, this will preserve the primary email address and display name of user1:

      $UserObject = Get-Mailbox User1
      Remove-Mailbox $UserObject -Confirm:$false
      New-MailContact -Name $UserObject.SamAccountName -DisplayName $UserObject.DisplayName -ExternalEmailAddress $UserObject.PrimarySmtpAddress.ToString()

  5. Hi Mike,

    I have really learnt a lot from the information you have kindly shared.. However I wondered if can help me, I want to convert some migrated exchange 2007 mailboxes to Mail enabled users. The mailbox has been migrated to o365. I need to keep the following attributes/ properties: ◦legacyExchangeDN Value from the on-premises mailbox.
    ◦mail The primary SMTP of the cloud mailbox.
    ◦msExchMailboxGuid Value from the cloud mailbox.
    ◦proxyAddresses Values from both the on-premises mailbox and the cloud mailbox.
    ◦targetAddress Read from the on-premises mailbox; the value is the primary SMTP of the cloud mailbox.

    There are two PS scripts from this link but as you can see from the comments lots of people have had issues with them… Can you shed some light on this or If possible can you provide me an alternative PS script I can use to accomplish the same task? Your help is much appreciated..

  6. This sollution is dangerous! When you create mail user with external email address from your internal domain Exchange would try to deliver email do your smarthost (from Send Connector).

  7. I am looking to convert Mailboxes that are forwarding via Mail Contact to a Mail User object. How can I pull in the external email address from the Mail Contact to the newly Enabled Mail User? Match the Mailbox ForwardingAddress and Mail Contact Identity?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s