Hey Exchange 2007, move the mailboxes, email me the log when you're done!
Here's a simple script for moving mailboxes, I talked about how to schedule an Exchange 2007 script in the last post. Here's what it does:
- Reads user aliases from a text file in the local directory (MoveMbx1.txt)
- Moves the mailboxes to a specified Server & Mailbox Store using 10 threads and suppressing the annoying "are you sure?" prompt
- Puts today date in a variable in format YYYYMMDD
- Get Exchange Migration Logs that have the above date in their name
- Emails the logs in plain text
Yes, we could certainly do more sophisticated things, such as find the smallest Mailbox Store and move users there, or format the XML logs better, but hey, I ran out of time. :-) Just copy the below to a .ps1 file.
#############################
# #
# Exchange 2007 Migration #
# Move-mailbox script #
# Date & Author #
# #
#############################
# NOTE: to run PowerShell scripts, you need to set the PS execution poloicy "set-executionpolicy unrestricted"
# load the list of users - this must be 1 user alias per line
# the user list file must be in the same directory as this script
$users = get-content MoveMbx1.txt
# move em to a specific target database using 10 threads
$users | move-mailbox -TargetDatabase "MailboxServer\StorageGroup01\MailboxStore01" -MaxThreads 10 -confirm:$false
# put today's date in a variable
$date=get-date -uformat "%Y%m%d"
# read today's migration log and store it as $EMailBody
$EmailBody = get-content "C:\Program Files\Microsoft\Exchange Server\Logging\MigrationLogs\*$date*.xml"
# when done, send us an email with the log text
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = "smtpserver.domain.com"
$mailmessage.from = ("<emailaddress>@domain.com")
$mailmessage.To.add("<emailaddress>@domain.com")
$mailmessage.Subject = “MoveMbx1.ps1 script has completed”
$mailmessage.Body = $EmailBody
$smtpclient.Send($mailmessage)
Comments
- Anonymous
October 27, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/10/27/hey-exchange-2007-move-the-mailboxes-email-me-the-log-when-youre-done/ - Anonymous
December 17, 2007
What is is that limits the number of threads you can use simultaneously when doing mailbox moves. I would like to move as many mailboxes as possible at the same time without destroying the network bandwidth.