CPU and memory usage in percentage for all processes in Powershell

Question:

Is there a way for viewing CPU and memory utilization in percentage for all running processes in PowerShell?

I have tried the following:

Along with it I have parsed this information and calculated memory usage percentage from total memory, but couldn’t get the same for CPU since by this command it show CPU time division in processes not utilization per se.

Used the following commands for total memory and total cpu utilization:

  1. TOTAL PHYSICAL MEMORY

    Get-WmiObject Win32_OperatingSystem | %{"{0}" -f $_.totalvisiblememorysize}

  2. TOTAL CPU UTILIZATION

    Get-WmiObject Win32_Processor | Select-Object -expand LoadPercentage

Any help would be appreciated. I need it in the following format:

Answer:

You can use the WMI object Win32_PerfFormattedData_PerfProc_Process to collect all this data.

If you need the memory in a percentage of total memory you can add the following at the start to get the total RAM in the system.

Then change the WorkingSetPrivate calculation to the following

Note the CPU stat in this WMI object is rounded to the nearest present and I have calculated the current used memory in Megabytes. For more information on this class see this link.

Source:

CPU and memory usage in percentage for all processes in Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply