gpt4 book ai didi

Powershell打印管道的内容?

转载 作者:行者123 更新时间:2023-12-01 11:03:14 25 4
gpt4 key购买 nike

我有以下脚本。

Get-Job | ? { $_.State -eq 'Completed' } | Remove-Job

我想在一个链式管道中显示删除的作业。以下脚本不起作用。

 Get-Job | ? { $_.State -eq 'Completed' } | Remove-Job | % { echo "Removed: $_" }

下面会出错。

 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

最佳答案

为了简单起见,您可以这样做:

get-job | ?{$_.state -eq "Completed"} | 
%{ Remove-Job $_; Write-host "Removed $($_.Name)" }

对于你想要做的事情,你必须做:

get-job | ?{$_.state -eq "Completed"}  | %{write-host "Removed: $($_.Name)"; $_} | 
Remove-Job

注意 $_,将作业传回管道。

关于Powershell打印管道的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8785373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com