Why am I getting the error for the code below:
Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object -ExpandProperty id | Receive-Job
Receive-Job : The input object cannot be bound to any parameters for
the command either because the command does not take pipeline input or
the input and its propertie s do not match any of the parameters that
take pipeline input. At line:1 char:147
+ Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq ‘Completed’} | Select-Object
-ExpandProperty id | Receive-Job <<<<
+ CategoryInfo : InvalidArgument: (2:PSObject) [Receive-Job], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.ReceiveJobCommand
However, this line works perfectly:
Receive-Job (Get-Job -Id 1 | Select-Object -ExpandProperty childjobs | Where-Object {$_.state -eq 'Completed'} | Select-Object -ExpandProperty id )
Any tips or helpful comments on the code are appreciated. I’m new to PowerShell.
Thanks
The problem is that
Select-Object -ExpandProperty idis sending aSystem.Int32which isn’t whatReceive-Jobis expecting for it’s ISA/HASA binding. Remove-ExpandPropertyso you keep theSystem.Management.Automation.PSCustomObjectwith the ID property.If you want to see the nitty gritty details of why a
System.Int32didn’t bind toReceive-Jobyou can useTrace-Command. This simplified example tries to bind aInt32(current process ID) toGet-Process.The output of this command is lengthy but it shows you everything PowerShell tried to do to bind the upstream object to the downstream cmdlet.