PowerCLI

 View Only
  • 1.  How to delete a broken VM which is still in 'Powered On' state?

    Posted Mar 13, 2017 04:18 PM

    This one is really a headscratcher gang.  I have a VM which should have been removed from a vCenter long ago.  I was attempting to remove it the normal way, but it wasn't going anywhere; just giving an error.  When I looked at the files in the VM's folder, nearly all were gone (vmx, log, vmdk).  There were a few files called -flat.vmdk, but I wasn't able to do anything with them.  I SSH'd into the host and found the VMs folder, but couldn't delete anything that way either.  All this, yet the VM is still showing as Powered On.

    I seem to recall that there was a way to remove VMs like this; i believe in CLI.  However, I can't remember it and now my mind has locked up in frustration for not being able to get this thing to leave.

    Does anyone know how to get rid of an unwanted, powered, yet corrupt VM?  Particularly, if anyone knows how to do it in our 'Tool of Tools' aka PowerCLI.

    Thanks in advance,:smileyangry::smileycry:

    Miguel



  • 2.  RE: How to delete a broken VM which is still in 'Powered On' state?

    Posted Mar 13, 2017 05:00 PM

    Hello, You can't directly delete or remove the powered on VM. To remove it or delete it, you must kill the VM instance process if unable to power it off normally from GUI.

    in my case (simmilar), I used below command/KB that worked like charm.. this may be useful for you as well.

    Login to the ESXi host and try to kill the VM process from here..

    esxcli vm process kill --type= [soft,hard,force] --world-id= WorldNumber

    Unable to power off the virtual machine in an ESXi host (1014165) | VMware KB



  • 3.  RE: How to delete a broken VM which is still in 'Powered On' state?

    Posted Mar 13, 2017 05:27 PM

    If the VM files are gone it might not be just a hung VM process.  I'd follow the KB that miguel says and see if you can find the process running on that host or any other host.  If you can't find that VM processes running anywhere, and vCenter thinks it is, vCenter is likely confused.  Restarting the inventory service might be a first step in that case and/or a rolling reboot of all hosts.



  • 4.  RE: How to delete a broken VM which is still in 'Powered On' state?

    Posted Mar 13, 2017 05:49 PM

    No need to enable SSH on the ESXi host, PowerCLI is your friend.

    $vmName = 'MyVM'

    $esx = Get-VMHost -VM $vmName

    $esxcli = Get-EsxCli -V2 -VMHost $esxName

    $killArgs = @{

        type = 'soft'

        worldid = $esxcli.vm.process.list.Invoke() | where{$_.DisplayName -eq $vmName} | Select -ExpandProperty worldID

    }

    $esxcli.vm.process.kill.Invoke($killArgs)



  • 5.  RE: How to delete a broken VM which is still in 'Powered On' state?

    Posted Mar 08, 2024 06:10 PM

    Typo: should be

       $esxName = Get-VMHost -VM $vmName

    Otherwise, thanks!