I have the following tiny PowerShell script that's meant to kill some certain processes on a remote machine:
$destPS = "mywebserver1"
$brokerPIDs = Get-Process -ComputerName $destPS | ?{$_.processname -eq "uniRQBroker" -or $_.processname -eq "uniRTE"}
foreach ($process in $brokerPIDs){
$thisId = $process.ID
Write-Host "Killing PID $thisId"
Invoke-Command $destPS {Stop-Process $thisId}
}
However, I'm getting the following error:
Cannot bind argument to parameter 'Id' because it is null.
As far as I can see, the pipeline shouldn't be interrupted by anything, so I'm not quite sure where I'm going wrong.