2016-06-09 70 views
0

我有PowerShell腳本,工作流程爲foreach -parallel。我在InlineScript塊的工作流程內設置了TimeoutSec在工作流程中處理文件錯誤

當我設置睡眠命令15秒,我得到了以下錯誤:

Microsoft.PowerShell.Utility\Write-Error : The activity has exceeded the 
specified maximum running time of 10 seconds. 
At create-new-vms:25 char:25 
+ 
    + CategoryInfo   : NotSpecified: (:) [Write-Error], TimeoutException 
    + FullyQualifiedErrorId : System.TimeoutException,Microsoft.PowerShell.Commands.WriteErrorCommand 
    + PSComputerName  : [localhost]

我希望寫這個錯誤日誌文件(每個錯誤一個文件,每foreach元素)。這個怎麼做?我必須添加到我的腳本中?

我的腳本:

$newvmlist = "test1", "test2" 

workflow create-new-vms { 
    param(
    [string[]]$vms 
) 

    foreach -parallel ($vm in $vms) { 
    $run = InlineScript { 
     # Create New VM 
     echo " " 
     echo " " 
     echo "___" 
     echo "VM Name - $Using:vm " 
     echo "----" 
     echo " " 
     echo " " 
     sleep 15 
    } -PSActionRunningTimeoutSec 10 

    $run 
    } 
} 

create-new-vms -vms $newvmlist 

回答

2

您可以使用ErrorVariable

create-new-vms -vms $newvmlist -ErrorVariable err 
$err |% {$i=0}{ $i++; $_ | out-file "$i.log" }