Invoke-Command -ComputerName $input -ScriptBlock {Get-Process -Name amazon-ssm-agent | foreach {Stop-Process -Force} -ErrorAction Stop}
When i pass the value to stop-process, its throwing error "cant bind null value to ID "
Stop-Process is not actually receiving any object the way it is written which is why you get that error. When in a ForEach-Object block you need to use $_ in your code block to represent each object being passed in. Just need to add $_ |
in front of Stop-Process
Invoke-Command -ComputerName $input -ScriptBlock {Get-Process -Name amazon-ssm-agent | foreach {$_ | Stop-Process -Force} -ErrorAction Stop}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.