I have the following script.
Get-Job | ? { $_.State -eq 'Completed' } | Remove-Job
I want to display the removed jobs in one chained pipes. The following script doesn’t work.
Get-Job | ? { $_.State -eq 'Completed' } | Remove-Job | % { echo "Removed: $_" }
And the following get errors.
Get-Job | ? { $_.State -eq 'Completed' } | % { echo "Removed: $_" } | Remove-Job
Remove-Job : The input object cannot be bound to any parameters for
the command either because t he command does not take pipeline input
or the input and its properties do not match any of the parameters
that take pipeline input. At line:2 char:81
+ Get-Job | ? { $.State -eq ‘Completed’ } | % { echo “Removed: $” } | Remove-Job <<<<
+ CategoryInfo : InvalidArgument: (Removed: System…n.PSRemotingJob:PSObject) [Re move-Job],
ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.RemoveJobComman
d
You can do like this to keep it simple:
For what you were trying to work, you have to do:
Note the
$_, passing the job back to the pipeline.