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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -