A VM appears as orphaned in the vCenter inventory when it has been directly deleted from the inventory of the host (in a vSphere-client session) instead of the vCenter one.
If the VM is not needed anymore the inventory must be cleaned so the vCenter database can be up-to-date.
Manually remove an object is simple but it can really get boring when it comes to do the same for several objects.
Among many, one method to remove orphaned VMs from vCenter inventory :
clear $vcenter = read-host “Please enter the FQDN of the vCenter you want to connect to” write-host “vc” $vcenter -ForegroundColor cyan Connect-VIServer $vcenter write-host “Looking for orphaned VMs…” -ForegroundColor Gray $OrphanedVM = @(get-vm |get-view | ?{$_.summary.runtime.connectionstate -eq “orphaned”}) if(!$OrphanedVM) {write-host “No orphaned VM found,leaving…” -ForegroundColor Gray;break} $userAnswer = read-host (“You are about to delete the following VM ” + $OrphanedVM.name + ” : . Do you confirm (y/n) ?”) if ($userAnswer.ToLower() -eq “y”) { foreach($VM in $OrphanedVM) { $VMName = $VM.name try { write-host “Removing VM $VMName…” -ForegroundColor Gray get-vm $VMName | Remove-VM $VM -Confirm:$false write-host “VM VMName successfully removed” -ForegroundColor Green } catch { write-host (“Failed to remove VM $VMname. Error : `n” + $_.Exception.message) -ForegroundColor Red } } } else { write-host “Leaving…” }