2012-03-16 53 views
2

爲什麼我收到的錯誤代碼如下:PowerShell的遠程作業

Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object -ExpandProperty id | Receive-Job 

接收-工作:輸入對象不能綁定到任何參數 命令或者是因爲該命令不拿管道輸入或 輸入及其屬性與 進行流水線輸入的任何參數都不匹配。在行:1 char:147 + Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$ _。state -eq'Completed'} |選擇對象 -ExpandProperty id |接收-工作< < < <
+ CategoryInfo:InvalidArgument:(2:PSObject)[接收-作業],ParameterBindingException + FullyQualifiedErrorId:InputObjectNotBound,Microsoft.PowerShell.Commands.ReceiveJobCommand

然而,該線作品完美:

Receive-Job (Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object -ExpandProperty id) 

任何提示或有用的意見的代碼表示讚賞。我是PowerShell的新手。

感謝

回答

4

的問題是,Select-Object -ExpandProperty id正在發送System.Int32這不是什麼Receive-Job期待爲它的ISA/HASA結合。刪除-ExpandProperty,讓您保留System.Management.Automation.PSCustomObject的ID屬性。

Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object id | Receive-Job 

如果你想看到的爲什麼System.Int32不結合Receive-Job可以使用Trace-Command細節問題細節。此簡化示例嘗試將Int32(當前進程ID)綁定到Get-Process

Trace-Command -Name ParameterBinding  -Option All -Expression { $PID | Get-Process } -PSHost 

此命令的輸出是冗長,但它顯示了一切的PowerShell試圖做到上游對象綁定到下游小命令。

+0

+1向他展示Trace-Command,教他如何釣魚:)。 – Marlon 2014-07-25 16:46:38