How to capture the exception raised in the scriptblock of start-job?

前端 未结 4 549
说谎
说谎 2020-12-29 23:08

I have the following script,

$createZip = {
    Param ([String]$source, [String]$zipfile)
    Process { 
        echo \"zip: $source`n     --> $zipfile\"
         


        
4条回答
  •  Happy的楠姐
    2020-12-29 23:23

    TLDR:

    # Works with both terminating and non terminating errors
    $j = start-job {1/0} | wait-job; try { rcjb $j -ErrorAction Stop } catch { "err $_" } 
    
    

提交回复
热议问题