invoke-command try/catch not working
for reason try/catch block doesn't work receive-job invoke-command computer not online. i'm not able catch error , handle it. shows normal error. ideas? see below details.
ps c:\> $job = invoke-command {hostname} -computername "notonline" -asjob;
ps c:\> $job | wait-job
id name state hasmoredata location command
-- ---- ----- ----------- -------- -------
25 job25 failed false notonline hostname
ps c:\> try { $result = receive-job $job } catch { "do stuff" + $_ }
receive-job : [notonline] connecting remote server failed following error message : winrm client cannot
process request because server name cannot resolved. more information, see about_remote_troubleshoo
ting topic.
@ line:1 char:28
+ try { $result = receive-job <<<< $job } catch { "do stuff" + $_ }
+ categoryinfo : openerror: (:) [receive-job], psremotingtransportexception
+ fullyqualifiederrorid : pssessionstatebroken
ps c:\>
thanks, figured out workaround
$result = receive-job $job -ea silentlycontinue -ev err
then test $err , handle error there.
Windows Server > Windows PowerShell
Comments
Post a Comment