In my lab I often destroy and re-create Nutanix clusters which sometimes leaves stale, inaccessible datastores as well as a bunch of inaccessible VM's. The following script will remove all these inaccessible VM's from inventory (Thanks to my colleague
Steven for this one):
Get-Cluster -Name $clustername | Get-VM | Get-View | Where {-not $_.Config.Template} | Where{$_.Runtime.ConnectionState -eq “invalid” -or $_.Runtime.ConnectionState -eq “inaccessible”} | %{Remove-VM -VM $_.Name}
Hi
ReplyDeleteJust found this.....saved me a load of time! Much appreciated.
Danny
Thank you for posting this, it worked for me! Had a NFS datastore I couldn't unmount and after this I was able to unmount.
ReplyDeleteThank you very much for saving me from a headache. There was a deleted machine in the VM cluster which was hanging out as inaccessible, this command solved my problem.
ReplyDelete