Get Process CPU Usage Using WMI

I recently blogged about another method to obtain a process’ CPU usage via Command Line: Get CPU Usage of a Process from Command Line

Heres a quick command line method for grabbing CPU usage of a process by process id, process name, or caption.

By Process ID

wmic path win32_perfformatteddata_perfproc_process where (IDProcess = '3488) get Name, Caption, PercentProcessorTime, IDProcess /format:list

By Process Name

wmic path win32_perfformatteddata_perfproc_process where (Name=iexplore) get Name, Caption, PercentProcessorTime, IDProcess /format:list

By Process Name (fuzzy)

wmic path win32_perfformatteddata_perfproc_process where (Name like %iexp%) get Name, Caption, PercentProcessorTime, IDProcess /format:list

Any processes with CPU time over 50%

wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 50) get Name, Caption, PercentProcessorTime, IDProcess /format:list

This entry was posted in Windows and tagged , , by Rich Kreider. Bookmark the permalink.

About Rich Kreider

Rich, founder of Techish.net, is an IT guy with over 8 years professional experience in systems and network administration, design and development. He is currently employed with Creative Technology in Western Pennsylvania for the past 4 years. He has been working with computer technology for over 15 years amd is currently studying for is VCP5 certification.

13 thoughts on “Get Process CPU Usage Using WMI

  1. Nice Job, I’ve been searching for this a long time and that one of CPU higher than is neat.

    One question tough, do you know if I can search for a specific process with CPU time over 50%?.

    Would be like the merger of 2 querys but I don’t know how to do it.

    Thank you

  2. This, for example, will find processes with CPU time over 5% in this example. Replace 5 with the % you would like. Let me know if this works for you.

    Note: This is one long line. Also, looks like there is a problem with this <code> or <pre> tag; It puts a space between the ^< ^> which it shouldn’t so if you copy and paste this it will give you an invalid query. Take the space out from between each of the ^< ^>.

    wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 5 and Name ^< ^> "_Total" and Name ^< ^> "Idle") get Name, Caption, PercentProcessorTime, IDProcess /format:list

    wmic process with cpu processor time greater than 5%

    I’m not sure I understand what you ask about searching for a specific process over 50%. Can you elaborate?

  3. Hey thank you for the really fast answer.

    The script works like a charm for me, but one last thing, could be modified so only look to one specific process?, for example the process iexplore

    Thank you

  4. I guess this is the one

    wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 5 and Name ^ “_Total” and Name ^ “Idle” and Name ^ “wmiprvse” and name=’w3wp’) get Name, PercentProcessorTime, IDProcess /format:list

    :-)

  5. wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 5 and Name ^< ^> "_Total" and Name ^< ^> "Idle" and Name LIKE "iexplore%") get Name, Caption, PercentProcessorTime, IDProcess, CreatingProcessID /format:list

    When you look at the results, you’ll see the CreatingProcessID in this now; Each tab runs under it’s own process ID. If you want to get details about the iexplore.exe process itself, you will want to query the PROCESS alias or win32_process path.

    wmic process where (handle = "2788") get /Value

    This will give you details on the actual iexplore.exe process.

  6. But at the end of the day there is a problem.

    For some reason sometimes I get “No Instance(s) Available”, even when I can see in the task manager that the process is right about my mark, also I just get 100 or 0 instead of the real value which should be between 5 to 50

    Thank you for your help

  7. You could try just logging some entries for the process to CSV format and reviewing them.

    logman create counter w3wp_proc -c "Process(w3wp*)% Processor Time"

    logman update w3wp_proc -si 10 -f csv -v mmddhhmm

    That will update every 10 seconds. To stop it, just: logman stop w3wp_proc

    Jump into c:perflogs and open up the CSV that will be in there for w3wp_proc. Maybe confirm if that counter isn’t broken by chance.

    • Rick Great blog here it has been very helpful.

      Do you know how I would be able to automatically terminate the process that the query returns?

      thank you,

      • Setup your query to return the handles (I just use a quick filter ‘name’ instead of processor usage)

        wmic process where (name like "chrome%") get handle /format:list

        Returns the handles and if you know the handle…

        wmic process where (handle = "2964") call terminate

        You could implement that into a batch script.

  8. So I’ve been trying to figure out how to determine process cpu utilization…and I cannot get an accurate number. When querying as you specified (as well as other sites), I cannot accurately get % CPU utilization of a process on a multi-processor OS. For example, if the process is using more than 25% of a 4-core server, the query only returns 100. Here is the query string: “Select * from Win32_PerfFormattedData_PerfProc_Process where Name=’sqlservr’”. Again, if the process is using a good portion of processor, it always says 100….I don’t understand why. Any thoughts?

  9. Pingback: Get CPU Usage of a Process from Command Line

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>