使用 Get-Process 错误地通过管道传输到 Stop-Process

Use Get-Process incorrectly piped to Stop-Process

我试图通过 powershell 在一行中停止多个 chrome 实例,但出现奇怪的行为:

Get-Process -Name chrome | stop-process $_

Returns 一个错误:

Cannot link paramter Id because it is null.

但是我有 8 个进程 运行,我可以在第一个进程上发出停止进程。

所以我不明白这是怎么回事。 (Windows 7) 有什么想法吗?

只需将 Get-Process cmdlet 通过管道传输到 Stop-Process 省略 $_:

Get-Process -Name chrome | stop-process