Tuesday, October 6, 2009

KillProcess

Who needs to kill processes on occasion?  Everyone, right?  Well, I do at least.  Here comes a oneliner.

ONELINER

gps | ? { $_.Name -match "%APPNAME%" } | % { $_.Kill() }

PEICE BY PEICE
gps
Alias for Get-Process.  Gathers all processes currently running on the local machine.  This can also be used to kill remote processes by adding -Computer %COMPUTER% after gps.

? { $_.Name -match "%APPNAME%" }
Input the app name to kill in place of %APPNAME%.  This will only return applications with the given name.
NOTE:  %APPNAME% must not contain the file extension.  i.e. EXCEL instead of EXCEL.EXE

% { $_.Kill() }
The Kill method of Get-Process shuts down the particular instance that is being handled.  Therefore, this will kill each instance that is passed through the pipe.

ALIASES
gps = Get-Process
? = Where-Object
% = ForEach-Object

0 comments: