Exchange 2007 Move-Mailbox Report

As we migrate our mailboxes over from Exchange 2003, to Exchange 2007, we've been asked numerous times for reports detailing the time/size of each mailbox moved. Lucky for us, Exchange does a wonderful job documenting the move (when you use move-mailbox to do so). Unfortunately for most humans, this data is in XML format. Readable, just not user friendly.

Hence, I created this nifty script, to read the XML files, then export a summary (in HTML and CSV format) of the moves. To get it running in your environment, you'll need to:

1. Modify the "$MigrationFolder" variable to point to the folder where the XML reports are located. We've put them on the D: drive.

Line 10: $MigrationFolder = "D:\Program Files\Microsoft\Exchange Server\Logging\MigrationLogs\"

2. Tweak the script for your displayname naming standard. We use an @ sign followed by the user's department (i.e. "Woodford, Eric@IT"). I've added an option to filter by the department entry. You may want to completely remove this filter.

Line 23: $totalMoved += $moved | ?{$_.result.errorcode -eq 0} |?{$_.mailboxname -match $dept}

3. Tweak the location of the reports.

Line 33 & 35: $filepath = "c:\support\scripts\migrationReport-"+$dept.replace("@","")+"-"+$todaystr

If you run the report without any commandline options, it will export all mailbox moves completed today for any department. Run it with date then department and it will output everything after the date, for the specific department. Hmm, since it is filtering on the mailbox name, department could be interchangeable for a specific mailbox username.

If ($args.count -eq 2) {
        $today = $args[0]
        $dept = ("@"+$args[1]).replace("@@","@")
        $usingArgs = $true
} else {
        $today = $(get-date).ToShortDateString()
        $usingArgs = $False
}

$MigrationFolder = "D:\Program Files\Microsoft\Exchange Server\Logging\MigrationLogs\"
$files = get-childitem $migrationFolder |?{$_.lastwritetime -ge $today} #| sort -descending lastwritetime
$totalmoved = @()

ForEach ($file in $files) {
        if ($file.name -match ".xml"){
                $LastAccess = $file.lastwritetime.Date.ToShortDateString()
                $ReportName = $MigrationFolder+$File.name
                [xml] $xml = get-content $ReportName
                $Moved = $xml."Move-Mailbox".TaskDetails.item
                if ($moved -ne $null) {                
                        $moved = $moved | %{add-member  -membertype Noteproperty -name "Date" -inputobject $_ -value $LastAccess -passthru}
                        if ($usingArgs) {
                                $totalMoved += $moved | ?{$_.result.errorcode -eq 0} |?{$_.mailboxname -match $dept}
                        } else {
                                $totalMoved += $moved | ?{$_.result.errorcode -eq 0}
                        }
                }
        }
}

$todaystr = $today.replace("/","-")
If ($usingArgs) {
        $filepath = "c:\support\scripts\migrationReport-"+$dept.replace("@","")+"-"+$todaystr
} else {
        $filepath = "c:\support\scripts\migrationReport-"+$todaystr
}
$totalMoved | select Date, mailboxname, mailboxsize, duration | convertto-html -title "Successfully Moved" | out-file -filepath ($filepath+".Html")
$totalMoved | select Date, mailboxname, mailboxsize, duration | export-csv -path ($filepath+".csv")

Comments

Failed User Script

Hi
I got script working. I have only small issues. It shows me which users are moved successfully.
How i can make script to show me which users failed during migration?

Dan

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.