If you need to terminate a hung-up Hyper-V virtual machine, this code can be used to retrieve the GUID of the virtual machine and then forcibly stop its process. The code makes use of the Get-VM cmdlet to retrieve the virtual machine’s GUID, followed by the Get-WmiObject cmdlet to search for the corresponding virtual machine process. Finally, the Stop-Process cmdlet is used to forcefully terminate the process.
$VMGUID = (Get-VM "VM_Name").ID
$VMWMProc = (Get-WmiObject Win32_Process | ? {$_.Name -match 'VMWP' -and $_.CommandLine -match $VMGUID})
Stop-Process ($VMWMProc.ProcessId) –Force