Get VM process id

The task

Imagine a standard operation – you need to expand vhdx size. It isn’t hard, right? Just:

  • go to Hyper-V manager,
  • right click the VM,
  • select settings,
  • select vhdx you want to expand,
  • click edit
  • then next
  • then select expand, click next
  • select new size,
  • then next
  • then finish.

Or you ca use PowerShell:

  1. Get VM hard disk location
  2. Resize VHD file

$VMName = 'SomeVM'
#Get VM disk path. Assuming there's only one VHD here
$VHDPath = Get-VMHardDiskDrive $VMName | Select-Object ExpandProperty Path
#Verify VHD information, including current size
Get-VHD Path $VHDPath
#Expand the disk
$newSize = 120GB
Resize-VHD Path $VHDPath SizeBytes $newSize

view raw


hosted with ❤ by GitHub

Trouble round the corner

But then the nasty gnome comes. The task doesn’t complete. Within 30 minutes. This is a dynamically expanding disk. Shouldn’t take longer than a few seconds. You try to stop the VM from within the guest OS. No go. You try to turn it off from Hyper-V host level. No go again. VM stays in ‘Stopped-Critical’ state. You want to try and kill the process vmwp.exe that is responsible for this VM. To get that, you first need VM GUID. GUI way is to go to VM folder and check for xml name:

Now, using ProcessExplorer we can add UserName column (View-> Select Columns) and check for given GUID:

Or you can use PowerShell

$VMName = 'SomeVM'
$GUID = Get-VM $VMName | Select-Object ExpandProperty id | Select-Object ExpandProperty Guid
$processID = Get-Process vmwp IncludeUserName | Where-Object {$_.Username -match $GUID} | Select-Object ExpandProperty ID

view raw


hosted with ❤ by GitHub

Not so happy ending

Now, killing vmwp process USSUALY works. It didn’t work this time and caused the vmms (Virtual Machine Management Service) to stuck. Which in the end caused the whole node to go crazy. But that’s another story.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s