I wrote this script for an Exchange 2003 to Exchange 2010 migration. The administrator wanted a way to communicate with users when their mailbox move was complete, as well as give him a way to monitor the progress of mailbox moves without sitting in front of the computer all night.

This script was tested in an Exchange 2010 SP2 environment where anonymous relay from specific hosts was allowed.

Purpose

The script accomplishes the following:
Create move requests for users specified in the $MailboxestoMove variable at the top
Moves each mailbox and monitors status every 30 seconds
Will output “Moving Users…” to the screen every 30 seconds while moves are in process
As a move completes with a “complete” status, an email is sent to the user – subject and body defined by variables at the top ($MessageSubject and $MessageBody). Then, the completed move request is cleared
As a move request completes with a“CompletedWithWarning” status, an email is sent to the user – the subject and body are defined by variables at the top ($MessageSubject and $MessageBody). Next, an email is sent to the administrator – the subject and body are defined by variables at the top($MessageSubjectWarning and $MessageBodyWarning) – which includes the move history report so you can investigate the warning. Then, the completed move request is cleared
If a move request completes with a “Failed”status, then an email is sent to the administrator – the subject and body are defined by variables at the top ($MessageSubjectFailure and $MessageBodyFailure) – which includes the move history report so you can investigate the warning. Then, the failed move request is cleared. NOTE: an email is NOT sent to the user
When all move requests have completed and cleared, an email is sent to the administrator – the subject and body are defined by variables at the top($MessagesSubjectComplete and $MessageBodyComplete). Once this email has been sent, the script ends.

Usability

To use the script, editing the values of the following variables is required:
$MailboxestoMove
$TargetDB
$SMTPServer
$SMTPFrom
Optionally, edit the message subject and body variables.

To run the script:

Open an elevated Exchange PowerShell window
Save the text file as a .PS1 file type rather than TXT
Navigate to the place the script is saved
Type .\MoveUsersandNotifyv2.7-Final.PS1
Script will begin running.

Feature Enhancements for a Future Version

There are a few things that I think could be improved in order to make this a really great tool.

  • Turn the script into a CMDlet. Doing that would involve wrapping the script in a function, parameterizing the 12 input variables, saving the script as a PSM1, and putting it in the /modules subfolder of your Exchange installation. If anyone does this before I get around to it, please post the updated script.
  • The script does not handle move requests that are suspended or automatically suspended. It completely ignores them. Additional code would need to be written to add script blocks to handle these two move request status types
  • The script assumes that there are no existing move requests when it begins running. If you run the script while there are existing requests, the script will get stuck in an infinite loop because it doesn’t know of the existing request.

The Script