Search This Blog

2013-11-04

Recoverring and Fixing VMs in an Inaccessible or Unknown State

If an NFS datastore is inaccessible for a prolonged period of time when a VM is off there is a bug in VM inventory that causes machines to be recognized as either inaccessible/unknown. The below is a fix that allows you to resolve this issue without having to reboot the machine and continue operations.

The fix is in 5.1u1 Build 1065491

http://blog.mattvogt.net/2013/02/08/vms-grayed-out-after-nfs-datastore-restored/

#Get Inaccessible Virtual Machines
$VMs = Get-View -ViewType VirtualMachine | ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"} | select name,@{Name="GuestConnectionState";E={$_.Runtime.ConnectionState}}
 
write-host "---------------------------"
Write-host "Inaccessible VMs"
write-host "---------------------------"
 
$VMs
 
#Reload VMs into inventory
Get-View -ViewType VirtualMachine | ?{$VMs} | %{$_.reload()}
 
#Show new state of reloaded VMs
$ReloadedVMs = Get-View -ViewType VirtualMachine | ?{$VMs} | select name,@{Name="GuestConnectionState";E={$_.Runtime.ConnectionState}}
 
write-host "---------------------------"
write-host "Reloaded VMs"
write-host "---------------------------"
 
$ReloadedVMs

No comments:

Post a Comment