Create a PowerShell Module
Recently I came across an issue on our Hyper-V Cluster. One of the VM was stuck in the “Stopping” state. I had to force the VM to shutdown by kill its process on the Hyper-V host. To do so, I first find out the VM’s GUID and then kill the process with the same GUID. Needless to say, the whole process can be achieved with the PowerShell commands below. # Get the VM GUID and find the process with the GUID $VM = Get-VM -Name $VMName -ErrorAction Stop $VMGUID = $VM .Id $VMWMProc = ( Get-WmiObject Win32_Process | Where-Object { $_ .Name -match 'VMWP' -and $_ .CommandLine -match $VMGUID }) # Kill the VM process Stop-Process ( $VMWMProc .ProcessId) – Force This is a pretty short and simple script, which is perfect for making a module. We have number of Hyper-V hosts across our environment. Instead of copying the script around, module will help us better organize the code and make it more re-usable. I also like to share this small function with our glo