由於Symantec Antivirus(SEP)v14引起的超時,需要將我的代碼從直接呼叫更改爲啓動作業程序,因此我的腳本被掛起。接收作業與直接呼叫不同
此快照是這麼長時間工作的罰款:
$updateDaten = Get-HotFix -computername "myserver" | % { $_.psbase.properties["installedOn"].Value } | Group-Object | select-object Name
變化的開始作業preocedure完全打亂了生成的對象。 IM使用Google現在測試了兩天,但不能找出什麼是如此complicatet在處理作業對象:
function Get-HotfixesListAsJob($computer, $timeout){
$job = Start-Job { param($c) Get-HotFix -computername $c |
% { $_.psbase.properties["installedOn"].Value } | Group-Object
} -ArgumentList $computer
Wait-Job $job -Timeout $timeout
Stop-Job $job
Receive-Job $job
Remove-Job $job
}
$updateDaten = Get-HotfixesListAsJob -computer "myserver" -timeout 80
但是我不能夠得到同樣的結果回用接收-工作。我總是得到一些有線的工作對象,我不能像以前一樣提取數據。爲什麼結果如此完全不同?是否有可能將數據恢復到之前的對象而不是作業對象?
btw。這個有趣的文章沒有解決我的問題: https://learn-powershell.net/2014/06/27/quick-hits-did-i-really-lose-my-output-with-receive-job-by-not-usingkeep/
謝謝您的回答提前
您的代碼有效。首先在函數中,你不需要'select-object Name',所以你也可以獲得其他的屬性 - RunspaceId,Group等等。其次,'wait-job'的輸出也是由你的函數輸出的,你可能想'等待作業$ job -Timeout $ timeout | Out-Null'使其沉默。但Get-HotFix的結果從您的函數返回... – TessellatingHeckler
謝謝@TessellatingHeckler Wait-Job $ job -Timeout $ timeout | Out-Null真的解決了這個問題!輸出結果搞砸了返回的對象,我從來沒有考慮過這個行爲。不幸的是,它通常沒有記錄和危險! –