每当手动键入命令的参数时,都会替代参数可能已接受的任何管道输入。 不要强制 Windows PowerShell 为管道参数绑定选择其他参数。 请考虑以下示例:

PowerShell复制

Get-Process -Name Notepad | Stop-Process –Name Notepad

在此示例中,Get-Process 获取具有 Name 属性的进程对象并将此对象传递给 Stop-Process。 但在此示例中,已手动使用 –Name 参数。 这将停止管道参数绑定。 即使有接受其他属性的参数,Windows PowerShell 也不会查找其他参数来绑定输入。 上面的示例获取了 Windows PowerShell 想使用的参数,因此进程结束。

在这种情况下,且在大多数情况下,即使属性值与为参数指定的值匹配,也会出现错误。 针对上述命令,会出现以下错误:

PowerShell复制

Stop-Process : 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 properties do not match any of the parameters that take pipeline input.

错误具有误导性。 它显示“… 命令不接受管道输入。” 但命令的确接受管道输入。 在此示例中,你禁用了命令接受管道输入的功能,因为你手动指定了 Windows PowerShell 要使用的参数。