Copy the below Script into PowerShell script file and then run it in exchange PowerShell. before running change YourO365TenanetID and YourMailDomain sections with relevant information.
#---------------------------
$username = Read-Host -Prompt 'Type User name'
$email = Read-Host -Prompt 'Input SMTP ID'
$Date = Get-Date
Get-Mailbox -Identity $username | fl Email*
$confirmation = Read-Host "Do you need to disable user '$username' Mailbox before migration? [Y/N]"
if ($confirmation -eq 'y') {
Disable-Mailbox -Identity "$username"
}
Start-Sleep -Seconds 5
Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq “Disabled” } | ft
Start-Sleep -Seconds 4
$confirmation2 = Read-Host "Do you need to enable remote mailbox for '$username' ? [Y/N]"
if ($confirmation2 -eq 'y') {
Enable-RemoteMailbox $username -RemoteRoutingAddress $username@YourO365TenanetID -PrimarySmtpAddress $email@YourMailDomain
}
Start-Sleep -Seconds 5
Get-RemoteMailbox -Identity $username | fl Email*
Start-Sleep -Seconds 2
Set-RemoteMailbox "$username" -EmailAddressPolicyEnabled $true
Set-RemoteMailbox "$username" -EmailAddressPolicyEnabled $false
Set-RemoteMailbox "$username" -RemoteRoutingAddress $username@YourO365TenanetID -PrimarySmtpAddress $email@YourMailDomain
#---------------------------------------
No comments:
Post a Comment