Exchange 2010 Mailbox Move Status Script
Saturday, May 14th, 20112011-05-14 Updated
2011-05-04 Initial Post
This is my first real PowerShell script. I'm starting to do a lot more with PowerShell now and eventually I'd like to get good enough to write some functions.
I wanted more information such as mailbox size and move duration so I searched and found the cmdlet Get-MoveRequestStatistics. That gave me what I needed so I rewrote my original script.
#Last modified by SysAdmin-E.com, 2011-05-09 $strScriptVersion = "Script version: getMailboxMoveStat-v1.2.ps1, updated 2011-05-09`n--End of Script--" <# Gets mailbox move request statistics and e-mails it out. Also copies to CSV file in D:\MailboxMoveStatistics\ on the server running the script. NOTE: This script looks for mailbox move requests. If you clear all the move requests, this script will not find anything. Clear the move requests only before and after running this script to get the most accurate count. To schedule, use this command (adjust path and version number first): powershell -command "& 'C:\_AdminScripts\getMailboxMoveStat-vX.X.ps1'" I kept getting this error: Task Scheduler failed to start "\getMailboxMoveStat" task for user "AD-DOMAIN\USERNAME". Additional Data: Error Value: 2147750687. I had to go to the task's Settings tab and select either "Run a new instance in parallel" or "Stop the existing instance." Tested with PS v2 with Exchange Server 2010 SP1 on Windows Server 2008 R2 SP1. Use a Hub server for the SMTP host. A MB or CAS server does not have an SMTP service. NOTE: When viewing the e-mail, Outlook might remove extra line breaks (`n), by default, so deselect that option in Outlook. #> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 $strDateTimeLong = Get-Date -Format F $strDateTimeShort = Get-Date -Format yyyy-MM-dd-HH-mm #Change file path below. $strFileOutputPath = "D:\MailboxMoveStatistics\MailboxMoveStatistics_$strDateTimeShort.csv" #Command below is for exporting the information to CSV. Rearrange the column names to your liking. Get-MoveRequest -ResultSize Unlimited | Get-MoveRequestStatistics | Select Status, PercentComplete, DisplayName, Alias, TotalInProgressDuration, TargetDatabase, SourceDatabase, TotalMailboxSize, TotalMailboxItemCount, BadItemsEncountered, StartTimestamp, CompletionTimestamp, MRSServerName | Sort Status -Descending | Export-Csv $strFileOutputPath -NoTypeInformation $strStatusCount = "Completed: " + (Get-MoveRequest | Where {$_.Status -eq "Completed" }).Count + ", Total Move Requests: " + (Get-MoveRequest).Count + ".`n" $strCmdForEmailBody = Get-MoveRequest -ResultSize Unlimited | Get-MoveRequestStatistics | Select Status, PercentComplete, DisplayName | Sort Status -Descending | FT -AutoSize | Out-String #Change SMTP server below. $strSmtpServer = "exchange-01" #Change e-mail sender below. $strSmtpSender = "Exchange 2010 Mailbox Move Statistics <SysAdmin-E.com@SysAdmin-E.com>" #Change e-mail recipient(s) below. $strSmtpRecipient = "someone@SysAdmin-E.com" $strSmtpSubject = "Exchange 2010 Mailbox Move Statistics - $strDateTimeLong" $strSmtpBody = $strStatusCount + "A more detailed report is in the file $strFileOutputPath on $env:computername.`n" $strSmtpBody = $strSmtpBody + $strCmdForEmailBody + $strScriptVersion $objSmtpClient = New-Object System.Net.Mail.SmtpClient $objSmtpClient.Host = $strSmtpServer $objSmtpClient.Send($strSmtpSender, $strSmtpRecipient, $strSmtpSubject, $strSmtpBody) Exit