«

»

Oct 30 2016

HOWTO: Check CPU Usage of VMs with VMware Workstation

Do you use VMware Workstation on Windows?  Do you run more than a handful of VMs?  Have you ever had your host CPU pinned by one of the instances of vmware-vmx.exe but the only way you could figure out which VM was the issue was by logging into each one and checking CPU usage there?  I found myself in this situation and figured there had to be a better way.  I realized that each VM runs as its own separate vmware-vmx.exe process.  I further figured out that the .VMX file that includes the name of the running VM is part of the command line arguments used to call it.  Putting this information together, I wrote a simple PowerShell script that is intended to be run on the Windows Host that will show all running VMs and their current CPU usage.  Note that the totals are for each VM, not of the host.  This is why multiple VMs can show 100% usage.

The script is below:

# Show all running VMs in VMware Workstation along with the current CPU usage of each VM
# Home; VMware; CPU; Workstation; Report

$VMwareProcess = (Get-WMIobject win32_process -filter "name = ‘vmware-vmx.exe’") | select processid, commandline

$Results = @()

ForEach($Line in $VMwareProcess)
{
    $Results += [pscustomobject]@{
        ProcessId = $Line.processID
        VMPath = (((get-wmiobject win32_process -filter "processid = $($Line.processid)").commandline) -split "msgs=ui")[1]
         CPU = ((Get-WmiObject Win32_PerfFormattedData_PerfProc_Process | where-object{ $_.idprocess -eq $($Line.processid)})).PercentProcessorTime
    }
}

$Results | sort CPU –Descending

The results look like this:

image

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">