Last active
July 23, 2017 03:47
-
-
Save macfarmw/7432f6565f534ad9f1c786ea0cff0148 to your computer and use it in GitHub Desktop.
Output from Invoke-Command ScriptBlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
$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