The following snippet in Test-TargetResource:
else
{
throw "robocopy returned with errors! Exit code: $result! More info here:https://support.microsoft.com/en-us/kb/954404"
}
Should be:
else
{
throw "robocopy returned with errors! Exit code: $LASTEXITCODE! More info here:https://support.microsoft.com/en-us/kb/954404"
}
as it is in the Set-TargetResource.