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}