In some organizations when a user leaves the company or is moved to a new role their existing mailbox needs to be reassigned to their replacement. In other words, the mailbox belongs to the role and not the person.
If you just disabled the mailbox many Exchange properties are lost, include the e-mail addresses and LegacyExchangeDN address (which is used by Outlook and stored in the Outlook nickname cache for message delivery). So these addresses need to be manually copied to the new mailbox, the LegacyExchangeDN needs to be added as an X.500 (X500) address to allow users to reply to past messages from the mailbox and to prevent message delivery issues when using Outlook.
So I created this script to simplify the process.
Script: Reassign-Mailbox.ps1
#****************************************************************************************** # Created by Jason Sherry (izzy@izzy.org) 3/15/2012 # # Copies an existing mailbox properties and reassigns it to a new user and restores properties after reassigning # Source: http://izzy.org/scripts/Exchange/Admin/Reassign-Mailbox.ps1 #Import-Module ActiveDirectory # Only needed if copying groups, which script doesn't support yet param( [Parameter(Mandatory = $true)] [String]$CurrentUser, [Parameter(Mandatory = $true)] [String]$NewUser ) Try { $Mailbox = Get-Mailbox $CurrentUser -ErrorAction Stop Write-Host "Got mailbox info for" $Mailbox.DisplayName # $Groups = (GET-ADUSER -Identity $CurrentUser-Properties MemberOf | Select-Object MemberOf).MemberOf } Catch { "Error:" ; $error[0].Exception.Message return } Write-Host "Existing Mailbox Details:" $MBXStats = get-mailboxstatistics $Mailbox | select * $MBXStats #$MBXPerms = get-mailboxpermission $Mailbox | select * #$MBXPerms Disable-Mailbox $Mailbox.alias -confirm:$false Write-Host "Waiting 15 seconds for cache refresh" start-sleep 15 Connect-Mailbox $Mailbox.exchangeguid -database $Mailbox.database -Alias $Mailbox.mailnickname -user $NewUser $NewMailbox = Get-Mailbox $NewUser $Mailbox.EmailAddresses += [Microsoft.Exchange.Data.CustomProxyAddress]("X500:" + $Mailbox.legacyExchangeDN) Set-Mailbox $NewMailbox.identity -emailaddresspolicyenabled $False Set-Mailbox $NewMailbox.identity -emailaddresses $Mailbox.emailaddresses Set-Mailbox $NewMailbox.identity -emailaddresspolicyenabled $True #******************************************************************************************
Usage:
.\Reassign-Mailbox.ps1
Example:
.\Reassign-Mailbox.ps1 JohnDoe JaneDoe
The above example would do the following:
1. Copy the e-mail addresses from the JohnDoe
2. Disconnect the mailbox from this account JohnDoe
Note: When a mailbox is disconnected many properties for the mailbox are lost, include the e-mail addresses for it. The script copies the mailbox information to a variable first to prevent the loss of these properties.
3. Reconnect the mailbox to JaneDoe
4. Copy the e-mail addresses and X500 address into the newly reattached mailbox for JaneDoe
I see that you’re obtaining the groups and the MailboxPermissions but not doing anything with them. How can you use that to apply to the new mailbox if that were desired? thanks.
LikeLike
Parsing permissions is a challenge and I haven’t looked into doing anything with them. Those lines are commented out in the script since I don’t do anything with them, but left them in just in case others wanted to.
LikeLike