Check for process owner on remote machine and kill

2019-07-07 10:18发布

问题:

Hey I want to check on an remote computer for a process owner of a specific process and kill it when the owner is for example xyz. I already managed it to check for the owner but I don't know how to kill it when the owner is xyz.

What I have so far:

get-wmiobject -computername remotePC win32_process|where{$_.name -eq "firefox.exe"}|select name,@{n="owner";e={$_.getowner().user}}

回答1:

Get-WmiObject -Class Win32_Process -Filter "Name='firefox.exe'" -ComputerName remotePC | 
Where-Object { $_.GetOwner().User -eq 'xyz' } | 
Foreach-Object { $_.Terminate() }