Skip to content

Instantly share code, notes, and snippets.

@Swoogan Swoogan/Exec
Created May 13, 2015

Embed
What would you like to do?
Wrapping commandline tools in a scriptblock to improve error handling
function Exec([scriptblock]$cmd) {
$result = & $cmd
if ($LastExitCode -ne 0) {
throw $result[-50..-1] -join "`n"
}
else {
foreach ($line in $result) {
Write-Host $line
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.