Skip to content

Instantly share code, notes, and snippets.

@Kagre
Last active December 21, 2020 19:25
Show Gist options
  • Save Kagre/7a10fd8e73b098d27e57f13c09d09fb4 to your computer and use it in GitHub Desktop.
Save Kagre/7a10fd8e73b098d27e57f13c09d09fb4 to your computer and use it in GitHub Desktop.
#[switch]$AutoRun is a parameter in the host script that is used when the host-script is called by an automation context
#typical usage: if(!$?){throw-automated 'prevoius line is broken'}
funciton throw-automated([string]$Message,[int]$Offset=1){
try{throw $Message}
catch{
if(!$AutoRun){
$Here = $MyInvocation
$LineNo = $Here.ScriptLineNumber - $Offset
$Line = (gc $Here.ScriptName -TotalCount $LineNo)[-1]
write-host "`n$_`nAt $($Here.ScriptName):$LineNo char:1`n+$Line`n" -BackgroundColor Black -ForegroundColor Red
pause
}
throw
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment