Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Created January 7, 2022 16:41
Show Gist options
  • Save JohnL4/bb1c1b3e6b5663982c6d4e81fd10ef84 to your computer and use it in GitHub Desktop.
Save JohnL4/bb1c1b3e6b5663982c6d4e81fd10ef84 to your computer and use it in GitHub Desktop.
Catch and log an exception (for some value of "log") with a script stack trace for later debugging
# Wrap your entire script in a try-catch block:
try {
# Do stuff
}
catch {
Write-Error ("{0}`n{1}" -f $_, $_.ScriptStackTrace)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment