powershell - Try & Catch not working when using Invoke-Command -
there's strange issue in script. i'm invoking command on servers. if can't connect server (because it's offline or something) still want log (server offline > log.txt)
apparently, when error occurs in try
block, catch
block not executed.
to test this, wrote value computername
parameter doesn't exist. here's code:
try { invoke-command -computername hui -scriptblock $sb } catch { write-host "hello" }
but script never puts out "hello"
the exception psremotingtransportexception
. tried specify exception, didn't work
when set breakpoint @ invoke-command
line, ignores catch block. why?
it's not terminating error, never caught try
/catch
. add -erroraction stop
:
try { invoke-command -computername hui -scriptblock $sb -erroraction stop } catch { write-host "hello" }
Comments
Post a Comment