Get WMI class of a running process in windows powershell?

433 Views Asked by At

I am running a python script using "python script.py arg1 arg2 ...". I wanted to use powershell to check memory consumption of this script (process). The below command can't catch the python process. Looks like it isn't a win32_process?

Get-WmiObject win32_process -Filter "name like '%python'"

In this blog by Raymond Chen, it is dealing with win32_process class. Looks like my python process is not win32_process, because the above command doesn't catch it.

1

There are 1 best solutions below

0
js2010 On

You can use the win32_process wmi class for python, and the name has the .exe on the end, slightly different from get-process:

Get-WmiObject win32_process -Filter "name = 'python.exe'" | select name,commandline

name       commandline
----       -----------
python.exe "C:\Program Files\emacs\bin\python.exe"

Or

Get-WmiObject win32_process | ? name -eq python.exe | select name,commandline

name       commandline
----       -----------
python.exe "C:\Program Files\emacs\bin\python.exe"

Or in powershell 7, get-process has the commandline property:

get-process python | select name,commandline

Name   CommandLine
----   -----------
python "C:\Program Files\emacs\bin\python.exe"