Before VMware vCenter 6.5, deleting orphaned VMs was really easy. You just needed to connect with the VMware vSphere Client (the fat client) to the vCenter server, create a new folder, move the broken stuff in it, and delete the folder.
Well… on vCenter 6.5, that’s not possible anymore as you can’t connect with the vSphere Client on the vCenter server, just to the ESXi.
The only workaround for this was to use PowerCLI (version 6.5 can be downloaded from here)
After installing PowerCLI, start it from your Desktop or from the Start Menu and type:
Connect-VIServer -Server YourvCenterServer
You’ll now be prompted for credentials needed to login in vCenter.
The following command will show you all VMs registered in vCenter
Get-VM -Name *
And to delete the orphaned one(s)
Get-VM -Name YourOrphanedVMName | Remove-VM
To see all running VMs and a bunch of other info type:
Get-VM | select * | Out-GridView
When you deleted all your VMs, you should also check to see if the process left behind some crap like unused VMDKs.
Good luck!
thank you for sharing this 🙂
Works at first attempt. Thank you! 🙂
[…] https://victorhomocea.wordpress.com/2016/12/13/how-to-delete-orphaned-vms-on-vmware-vcenter-6-5/ […]
Thank you ! You really help me.
Great article! Took me forever to find it…Thanks!
Glad I could give something back to the community 🙂
While this method works, the problem only exists in the 6-5 Flash client. Another method is to utilize the HTML5 client. When browsing to an orphaned VM, you have the option to remove from inventory, just like the old C# client. The reasoning has to do with the underlying method invoked to get the list of VM’s. These two UI’s utilize different paths and calls to display the VM’s, which is why it doesn’t work using the Flash client.
Thanks for the comment Russ.
I don’t recall what was the client that got me into that issue but you could be right.
Haven’t migrated completely to the HTML5 client mostly due to lack of settings and because the interface is “too loose” (I’m one of those guys that prefer compact interfaces) 🙂
What if i have multiple VMs like 150 VMs to be deleted from vCenter. What is the command ?
Can you help with a command to delete multiple VMs from vcenter using VMWare PowerCLI, about 150 VMs in a text file.
Hi Serge, try this:
#####################################
Connect-VIServer -Credential (Get-Credential)
# All vms in vcenter
$vms = Get-VM
# VM names supplied by the admin
$vmnames = Get-Content vmnames.txt
# Array of VMs to be deleted
$array = @()
# Array of VMs non existent
$array1 = @()
# Multiple for-loop to compare the names and append in both the arrays.
foreach ($vmname in $vmnames)
{
foreach ($vm in $vms)
{
if ($vm.name -match ($vmname -replace “(OFF)”,””))
{
$array += “” | select @{l=’CSV_VMName’;e={$vmname}},@{l=’VC_VMName’;e={$vm.name}}
}
else
{
$array1 += Write-Host “$vmname does not exist in vcenter”
}
}
}
# Delete all the Stale VMs permanently
$array | % { Remove-VM $_.VC_VMName -DeletePermanently -Confirm:$false }
#####################################
This script is something I found on the web with a simple search. I did not had time to test it, but seems it will do the job. You’ll need to create a DeleteVMlist.ps1 and vmnames.txt in a folder, modify the with your actual vCenter hostname, then run the DeleteVMlist.ps1 from PowerCLI. You should be prompted to enter the credentials for connecting and deleting the VMs (permissions to delete VMs is required).
Have a test with a couple of dummy VMs.
Cheers!