We had an instance last year where our storage became unstable and HA tried to failover guests. The result was that there were phantom VMs that could only be seen when connecting to individual hosts. These phantom VMs would disappear when you would answer the “did you copy or move” question, but they would prevent the VMs from vmotioning until that question was answered. Here is a script to connect to each host, look for duplicate VMs and then answer the question.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
$vCenter=name $datacenter=dc Connect-VIServer $vCenter $vmhosts=Get-datacenter $dc | get-vmhost -State Connected Disconnect-VIServer -Server $vCenter -Confirm:$False $HostCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Current Host credentials", "root", "") $hash = @{} foreach ($vmhost in $vmhosts){ Connect-VIServer $vmhost.name -Credential $hostCred $vms=Get-VM | select Name, PowerState foreach ($vm in $vms) { $vmname = $vm.name $PowerState=$vm.PowerState $instance = @{ "$vmhost" = $PowerState; } if ($hash.ContainsKey($vmname)) { $hash[$vmname][$vmhost.name]=$PowerState } else { $hash.Add($vmname,$instance) } } Disconnect-VIServer $vmhost.Name -Confirm:$False } $i=0 foreach ($vmname in $hash.Keys){ if ($hash[$vmname].count -gt 1){ $vmname $i++ foreach ($myhost in $hash[$vmname].keys){ if ($hash[$vmname][$myhost] -eq "PoweredOff"){ $myhost Connect-VIServer $myhost -Credential $HostCred Get-Vmquestion -VM $vmname | Set-VMQuestion -Option "I moved it" -Confirm:$false Disconnect-VIServer $myhost -Confirm:$false } } } } |