Trapping Errors when Automating Metalogix Content Matrix via Powershell

Trapping Errors when Automating Metalogix Content Matrix via Powershell

One thing I sometimes need to do is move content around my SharePoint environment, and in some cases this is a regular thing. To help I have the migration tool Metalogix Content Matrix, which allows me to move content with it's metadata intact.

A cool feature of Content Matrix is that after doing a move via the UI you can choose to script that move into Powershell, allowing you to repeat the process. This was attractive as it allows me to work in a certain amount of automation rather than purely using the UI. For example I can change this powershell so that I perform a query to retrieve the IDs that need to be moved, and feed these into the Metalogix script. This is a big time saver because I find the Content Matrix UI really slow sometimes.

Though I liked being able to automate my content moves in this way it would be nice to check whether the move was successful, and take action in my script depending on the result. Looking at the Metalogix website I couldn't find any documentation on this, but luckily there is a way which I'll document here! :)

First off, running the help command against the Copy-MLSharePointFolder cmdlet showed me some parameters not listed on their website; -ErrorVariable -WarningVariable -OutVariable

Through trial and error I found that the variable name needs to be provided like so, without $;

$myOutVariable = ""

-OutVariable "myOutVariable"

OutVariable is the one to use, I don't see anything getting returned in the other two.

Further trial and error I discovered I was getting an Arraylist returned with one element of type Metalogix.Jobs.JobSummary

This is not documented anywhere, so I used decompiler to discover the useful properties which turned out to be within Metalogix.Actions.dll;

int Warnings
int Failures
string ResultsSummary
int Skipped
string StatusMessage
int MissingOnSource
int MissingOnTarget
int TotalCompletions
string JobID
Dictionary<string, long> CompletionDetails
DateTime Started
DateTime Finished

So putting it all together I define a variable in my script called;

$outML = ""

Plus I add a parameter to the Copy-MLSharePointFolder cmdlet in the metalogix script like so;

-OutVariable "outML"

I can then read intelligent numbers on failures and completions and take action in my script as necessary;

$failureCount = $outML.Item(0).Failures
$completionCount = $outML.Item(0).TotalCompletions

If (($failureCount -lt 1) -and ($completionCount -gt 0))
{
#blah blah
}

Hope this is helpful to someone!

Happy SharePointing!

Disclaimer: The software, source code and guidance on this website is provided "AS IS"
with no warranties of any kind. The entire risk arising out of the use or
performance of the software and source code is with you.

Any views expressed in this blog are those of the individual and may not necessarily reflect the views of any organization the individual may be affiliated with.