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 @domain.com. 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 +"@domain.com") -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…)
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.
Steve
Thanks for the comment Steve. What would x500 buy us? is this for cached OAB and nk2 cache purposes?
As for the static DC binding, I agree – it doesn’t solve all the problems. One error I ran into was due to PS remoting: “Pipelines Cannot be Executed Concurrently”. For this, I found: http://www.mikepfeiffer.net/2010/02/exchange-management-shell-error-pipelines-cannot-be-executed-concurrently/
Hi Mike, Thanks for the post I think this will work with my scenario as I have mailboxes I need to convert to remote mailboxes preserving the legacy attributes but I need to use a csv file to target the users which need to be modified, can you provide with the complete script to leverage a csv
Thank you!
Cesar
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
HI did you ever receive a way to use a csv file with this script?
This saved me this morning. Thank you.
Great script! Would this preserve the memberof attribute?
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 + “@domain.com”) -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
}
}
Peter-
Would there also be a way to pull all existing x500 addresses and add them on to the newly converted mail-enabled user? We have gone thru some migrations before where the LegacyExchangeDN was already added as an x500 and we would need to preserve those.
Chris, check this out: http://blogs.technet.com/b/mbaher/archive/2008/02/17/auto-complete-reply-ability-i-need-my-x500.aspx
Great stuff. Helped me a lot to develop a script for interforest migration.
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.
Thanks,
Ashish
Email: ashish.kumar@e-pspl.com
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()
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.
http://community.office365.com/en-us/wikis/exchange/845.aspx
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..
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).
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?