This powershell statement looks for a long commandline string from a process java.exe - it uses the string server1 to trap this specific process. It returns the words Processid
and Commandline
with its relative values.
gwmi win32_process | select Processid,Commandline | where-object CommandLine -match "server1"
returns this line where 15112
is all I need:
Processid Commandline
--------- -----------
15112 D:\ ..a long command string.
How would you trap the single PID number returned from the above PS statement in a variable to run a taskkill /pid $PIDNUM
on ? Not sure how to extract that single number from the statement.