我一直在玩PS3 RC中的PowerShell工作流程,到目前爲止,我已經戀愛了。但是,您可以在工作流程內部不能使用的種類有很多限制。我現在掛上的是$ Error變量。當調用我的工作流,我收到以下錯誤:在工作流程中發現錯誤
The variable 'Error' cannot be used in a script workflow.
有誰知道如何捕獲錯誤的內部工作流程上,如果你不熟悉工作流程捕獲錯誤的替代方法文本,或建議?我一直在四處搜尋,幾乎找不到有關工作流程細節的信息。謝謝!
我試圖做這樣的事情:
workflow Get-LoggedOnUser{
param([array]$computers,[System.Management.Automation.PSCredential]$credential)
foreach -parallel($computer in $computers) {
$response = $null
$errorMessage = $null
If (Test-Connection -ComputerName $computer -count 1 -quiet) {
Try {
$ErrorActionPreference = "Stop"
$response = Get-WMIObject -PSCredential $credential -PSComputername $computer -query "Select UserName from Win32_ComputerSystem"
$Error
}
Catch {
$errorMessage = $Error[0].exception
}
Finally {
$errorActionPreference = "Continue"
}
}
Else {
$errorMessage = "No response"
}
$output = [PSCustomObject]@{
Name = $computer
User = $response.UserName
Error = $errorMessage
}
$output
}
}
我確實嘗試了你的方法,但無法使其工作。 $ _變量保持空白。我本來可能做錯了什麼。無論如何感謝您的迴應!未來我會記住這個方法。 – 2012-07-20 16:07:17
至少在PS V4中這對我有效。 – Trondh 2014-04-27 14:52:36