1

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.

Jayanth
  • 115
  • 1
  • 11
  • 1
    Does this answer your question? [How to get Command Line info for a process in PowerShell or C#](https://stackoverflow.com/questions/17563411/how-to-get-command-line-info-for-a-process-in-powershell-or-c-sharp) – zett42 Dec 05 '22 at 09:02
  • It does not. I tried the same command and it did not work for me. The reason could be that the python program is not a win32_process. Not sure how to find the right class for my program. – Jayanth Dec 05 '22 at 12:31
  • I have updated question to ask how to get WMI class of the running process. Answer to that will help me find the command line args for it. – Jayanth Dec 05 '22 at 12:38
  • I believe the name would be `python.exe`. – js2010 Dec 05 '22 at 13:54
  • Btw get-process in powershell 7 has a commandline property. – js2010 Dec 05 '22 at 15:41

1 Answers1

1

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"
js2010
  • 23,033
  • 6
  • 64
  • 66