Skip to content

Instantly share code, notes, and snippets.

@macfarmw
Last active July 23, 2017 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macfarmw/7432f6565f534ad9f1c786ea0cff0148 to your computer and use it in GitHub Desktop.
Save macfarmw/7432f6565f534ad9f1c786ea0cff0148 to your computer and use it in GitHub Desktop.
Output from Invoke-Command ScriptBlock
...
$results = Invoke-Command -ComputerName localhost -Authentication Credssp -Credential $credential -ScriptBlock {
$exitCode = 0
$output = @()
try {
$output += "Copying files..."
Copy-Item "$Using:workspace\AMERICAS\Netlogon\*.*" \\USDC4\NETLOGON -Force -ErrorAction Stop
Copy-Item "$Using:workspace\APAC\Netlogon\*.*" \\SGDC2\NETLOGON -Force -ErrorAction Stop
Copy-Item "$Using:workspace\EMEA\Netlogon\*.*" \\UKDC3\NETLOGON -Force -ErrorAction Stop
$output += "Files copied"
}
catch {
$exitCode = 1
$output += "Error: $($_.Exception.Message)"
}
# Return the results of this script block so the outer script can check what happened...
[PSCustomObject]@{ ExitCode=$exitCode; Output=$($output -join [System.Environment]::NewLine) }
}
$results.Output
$exitCode = $results.ExitCode
}
catch {
$_.Exception.Message
$exitCode = 1
}
exit $exitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment