Exchange 2007 Migration Log Parser

I got a request recently to find out what mailboxes moved and when that took place.  I knew that each batch of mailbox moves creates two log files; a plain text log and an xml.  Since I knew right where they were, I decided to see what I could do about getting valuable data from them.

I’m not a huge supporter of XML as a format just because I’ve been behind the times for so long.  That will probably change with the advent of PowerShell and the availability of the XmlDocument definition.

I’m only just getting started, but I had some fun with this.

# --------------------------------
# ParseMigrationLogs.ps1
# --------------------------------
# Author: Kevin M. Sparenberg
# Date:    2010-11-12
# --------------------------------
 
# Location of the XML Migration Log Folders (must keep the '*"' at the end"
$MigrationLogPath = "D:Program FilesMicrosoftExchange ServerLoggingMigrationLogs*"
$MigrationLogs    = Get-ChildItem $MigrationLogPath-Include move-Mailbox*.xml | Sort-ObjectLastWriteTime-Descending
#$MigrationLogs
 
# Build new Empty Collection
$MailboxMigrations= @()
 
# Cycle through each log file in the folder
ForEach ( $Log in $MigrationLogs )
{
    Write-Host Processing $Log.Name
    
    # Import the Data as a XmlDocument
    $xmldata= (Get-Content$Log.PSPath )
 
    # Get the Batch Start Time
    $StartTime=$xmldata.SelectNodes("move-Mailbox/TaskHeader") | Select-Object StartTime
    
    # Get the details on each of the items (mailbox moves)
    $UserMoves=$xmldata.SelectNodes("move-Mailbox/TaskDetails/Item")
 
    ForEach ( $Move in $UserMoves )
    {
        # Create a new Object to hold my findings
        $MoveInfo = New-ObjectPSObject
        # Add a bunch of stuff to the object
        $MoveInfo | Add-Member -MemberType NoteProperty -NameBatchStartTime -Value $StartTime.StartTime
        $MoveInfo | Add-Member -MemberType NoteProperty -NameDisplayName    -Value $Move.MailboxName
        $MoveInfo | Add-Member -MemberType NoteProperty -NameSize           -Value $Move.MailboxSize
        $MoveInfo | Add-Member -MemberType NoteProperty -NameDuration       -Value $Move.Duration
        $MoveInfo | Add-Member -MemberType NoteProperty -NameSourceDatabase -Value $Move.Source.SourceDatabase
        $MoveInfo | Add-Member -MemberType NoteProperty -NameTargetDatabase -Value $Move.Target.TargetDatabase
        $MoveInfo | Add-Member -MemberType NoteProperty -NameStatus         -Value $Move.Result.InnerText
        $MoveInfo | Add-Member -MemberType NoteProperty -NameError          -Value $Move.Result.ErrorCode.ToString()
        
        # Add that object to the collection
        $MailboxMigrations += $MoveInfo
        
    }
 
}
 
# Export the collection to a CSV file
$MailboxMigrations | Export-CSV $env:ComputerName"_MigrationSummary.csv" -NoTypeInformation:$true

I appreciate any comments or feedback.  This is probably not my final version, but it’s a place to start.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.