为什么我收到以下代码的错误:
Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object -ExpandProperty id | Receive-Job
Receive-Job:输入对象不能绑定到任何参数 该命令要么是因为命令不接受管道输入,要么是 输入及其属性与任何参数都不匹配 拿管道输入。在行:1字符:147 + Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$ _.state -eq'Completed'} |选择-对象 -ExpandProperty id |接收作业<<<<<
+ CategoryInfo:InvalidArgument:(2:PSObject)[Receive-Job],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的新手。
由于
答案 0 :(得分:4)
问题在于,Select-Object -ExpandProperty id
正在发送System.Int32
,而Receive-Job
并不是-ExpandProperty
期待它的ISA / HASA绑定。移除System.Management.Automation.PSCustomObject
,以便将Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object id | Receive-Job
与ID属性保持一致。
System.Int32
如果您想查看Receive-Job
未绑定到Trace-Command
的原因的细节,可以使用Int32
。此简化示例尝试将Get-Process
(当前进程ID)绑定到Trace-Command -Name ParameterBinding -Option All -Expression { $PID | Get-Process } -PSHost
。
{{1}}
此命令的输出很长但它显示了PowerShell尝试将上游对象绑定到下游cmdlet的所有内容。