Sorry, forgot to include environment details: On premise Exchange 2010 SP3 UR11 single server hosting Hub/CAS/Mailbox roles.
Thanks, Geoff From: [email protected] [mailto:[email protected]] On Behalf Of Orlebeck, Geoffrey Sent: Wednesday, December 30, 2015 9:20 AM To: '[email protected]' Subject: [Exchange] New AD Acct - Migrate Mailbox: Recently we have contractors/consultants becoming employees on a semi-regular basis. This employment status conversion requires a new AD account, but they can keep their old mailbox. I am having hit-or-miss success with disabling the mailbox and reconnecting it to the new AD account. I'm wondering if there is a better way than I have attempted below. My PowerShell skills are far from expert, so any helpful suggestions or reasons you can help me understand why this only works some of the time would be welcomed. I recently added the 10min pause because it seemed sometimes the disconnected mailbox didn't appear until a few minutes later. Is there a normal/expected delay between disabling a mailbox and when it shows as disconnected? I'll stop asking questions for now, here is the code for any constructive suggestions. Thank you. -Geoff Function Update-Employee{ param( $Username, $NewUsername, $MoveEmail ) # Get User information from AD # Import-Module ActiveDirectory $User = Get-ADUser -Identity $Username -Properties DisplayName $Original = Get-ADUser -Identity $Username -Properties DisplayName $NewUser = Get-ADUser -Identity $NewUsername -Properties DisplayName # Connect to Exchange Server # $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeserver.domain.org/PowerShell/ -Authentication Kerberos Import-PSSession $Session # Update user information # Set-Mailbox -Identity $User.SamAccountName -Name "$($User.Surname)-OLD, $($User.GivenName)" Disable-Mailbox -Identity $User.Name -Confirm:$False Get-MailboxDatabase | Clean-MailboxDatabase # Insert pause for disabled mailbox # Sleep -Seconds 600 Set-ADUser $User.SamAccountName -DisplayName "$($User.Surname)-OLD, $($User.GivenName)" -Surname "$($User.Surname)-OLD" -Enabled $False Get-ADUser $Username | Move-ADObject -TargetPath "OU=zAspire Disabled Users,DC=aspirehealthplan,DC=org" Get-ADUser $NewUsername | Set-ADUser -DisplayName "$($Original.Surname), $($Original.GivenName)" -Surname "$($Original.Surname)" Get-ADUser $NewUsername | Set-ADUser -Enabled $true # Connect disconnected mailbox # If($MoveEmail){ Connect-Mailbox -Identity $Original.DisplayName -User $NewUser.SamAccountName -Alias $Newuser.SamAccountName -Database AHPMAILDB Set-Mailbox $NewUser.SamAccountName -Name "$($Original.Surname), $($Original.GivenName)" -EmailAddressPolicyEnabled $False -PrimarySmtpAddress "$($Original.GivenName).$($Original.Surname)@aspirehealthplan.org" } # Disconnect from Exchange server # Get-MailboxDatabase | Clean-MailboxDatabase Remove-PSSession $Session } Example use (John Doe): Update-Employee -Username Temp1234 -NewUsername JD5678 -MoveEmail $True Confidentiality Notice: This is a transmission from Community Hospital of the Monterey Peninsula. This message and any attached documents may be confidential and contain information protected by state and federal medical privacy statutes. They are intended only for the use of the addressee. If you are not the intended recipient, any disclosure, copying, or distribution of this information is strictly prohibited. If you received this transmission in error, please accept our apologies and notify the sender. Thank you. Confidentiality Notice: This is a transmission from Community Hospital of the Monterey Peninsula. This message and any attached documents may be confidential and contain information protected by state and federal medical privacy statutes. They are intended only for the use of the addressee. If you are not the intended recipient, any disclosure, copying, or distribution of this information is strictly prohibited. If you received this transmission in error, please accept our apologies and notify the sender. Thank you.
