I am trrying to run a scheduled job to delete a cloned VM.
Every time I run Get-VM <..........VM Name...........> | remove-vm -deletefromdisk -confirm:$false
But the VM goes Orphaned - files are deleted from the disks.
also tried
Get-VM <.....VM Name...........> | Remove-VM -DeletePermanently -Confirm:$false
gives same results.
That must mean you are connected to the ESXi server and not the vCenter.
You could check/display the contents of the $global:defaultviservers variable to verify.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes logged onto ESXi rather than vCentre, with root credentials.
So take it needs to be a connect-viserver to vCentre?
yes, to get it cleaned from the vCenter DB we've to connect to the vCenter and perform delete.