Recovering variables from try/catch in Powershell -
i having problem restart script. trying sent out restart-computer command series of servers , capture failures can retry them in manner (in case through vic).
here code snippet
try { restart-computer -computername $_.servername -credential $cred -force -erroraction stop } grab [system.exception] { #create output object $output = [pscustomobject] @{ servername = $_.servername domain = $_.domain environment = $_.environment vic = $_.vic } export-csv -inputobject $output -path c:\temp\vicredo.csv -force -notypeinformation } }
the issue here $_ variables don't create downwards grab block, have no way of writing them "retry list". can think of way works?
when encounters terminating error, original pipeline stopped. pipeline started, , what's in pipeline error.
you can around switching using foreach loop.
powershell
No comments:
Post a Comment