-
-
Save Swoogan/ddaee2b8af239def6717 to your computer and use it in GitHub Desktop.
Wrapping commandline tools in a scriptblock to improve error handling
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
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