【问题标题】:Stop-Process doesnt take -id or input from piped valueStop-Process 不接受 -id 或来自管道值的输入
【发布时间】:2021-02-04 07:44:54
【问题描述】:

Invoke-Command -ComputerName $input -ScriptBlock {Get-Process -Name amazon-ssm-agent | foreach {Stop-Process -Force} -ErrorAction Stop}

当我将值传递给停止进程时,它的抛出错误“无法将空值绑定到 ID”

【问题讨论】:

    标签: windows powershell


    【解决方案1】:

    Stop-Process 实际上并没有按照它的编写方式接收任何对象,这就是您收到该错误的原因。在 ForEach-Object 块中,您需要在代码块中使用 $_ 来表示传入的每个对象。只需在 Stop-Process 前面添加$_ |

    Invoke-Command -ComputerName $input -ScriptBlock {Get-Process -Name amazon-ssm-agent | foreach {$_ | Stop-Process -Force} -ErrorAction Stop}
    

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      相关资源
      最近更新 更多