Last active
December 21, 2020 19:25
-
-
Save Kagre/7a10fd8e73b098d27e57f13c09d09fb4 to your computer and use it in GitHub Desktop.
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
#[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