Re:Stronger Shell
by useerup on Wednesday August 12, 2015 @03:22PM
(#10050021)
Silly me, I assumed that the executable path was the requirement. My bad.
If you need to find a process just by it's name, it is even simpler: Just indicate the process name (possibly with wildcards) to Get-Process (alias ps):
ps Notepad++ | kill
Actually, kill (alias for Stop-Process) takes a name parameter directly, so the "kill" line from the script could be written as simply
kill notepad++
But your question is actually really good, because what if we did not know the neither the process name nor the executable, but -say- only the Window title?
Get-process (alias ps) will produce a sequence objects describing the running processes.
If I want to know what properties those objects have that I can possibly filter on, I
can pipe the objects through the Get-Member cmdlet (alias gm):
ps | gm
This produces a table-formatted list like this (shortened):
Lo and behold, there is a property called MainWindowTitle. So to stop a process by it's main window title I could write:
ps | ? MainWindowTitle -eq 'Deepthought Main Console' | kill
That is, find all processes, pipe them through a filter selecting only those where the MainWindowTitle equals the desired text, and pipe those processes to the Stop-Process cmdlet
ps Notepad++ | kill
Actually, kill (alias for Stop-Process) takes a name parameter directly, so the "kill" line from the script could be written as simply
kill notepad++
But your question is actually really good, because what if we did not know the neither the process name nor the executable, but -say- only the Window title? Get-process (alias ps) will produce a sequence objects describing the running processes. If I want to know what properties those objects have that I can possibly filter on, I can pipe the objects through the Get-Member cmdlet (alias gm):
This produces a table-formatted list like this (shortened): Lo and behold, there is a property called MainWindowTitle. So to stop a process by it's main window title I could write: That is, find all processes, pipe them through a filter selecting only those where the MainWindowTitle equals the desired text, and pipe those processes to the Stop-Process cmdlet