Sunday, 1 May 2016

Reconnect Invalid or inaccessible VMs

Recently we had issues with NFS storage. NFS storage was disconnecting intermediately from ESXi host and until we fix Storage issue on NetApp, many VMs status become “inaccessible” or “invalid”
Also some VMs were running fine but VMs disk size changed to 0 MB. We could access these VMs using Remote desktop and see the correct disk size in Guest OS. But vCenter was showing disk size as 0 MB for all Disk of affected VM.
How to reconnect invalid or inaccessible VMs?
Manual way -
  1. Remove invalid or inaccessible VM from vcenter inventory.
  2. Browse datastore where VM was stored and go to VM folder.
  3. Find the VMs .vmx file and add it to inventory.
This manual way is easy and simple to follow if you have only couple Of VMs.
But in my case due to storage issues many more VMs were affected.
How to fix it using PowerCLI -
#Connect vCenter server
#Find all invalid and inaccessible VMs in vCenter and reload it.
(Get-View -ViewType VirtualMachine) |?{$_.Runtime.ConnectionState -eq "invalid"  -or $_.Runtime.ConnectionState -eq "inaccessible"} |%{$_.reload()}
Above script will also fix VMs 0 MB disk issue.
To fix 0MB disk size VMs manually, you can migrate VMs from one Host to another and during upgrade process VM will reregister on new node and update disk details.
for single VM, you can do this also.
>Get-VM  vlabVM2k8 | Get-View | %{$_.reload()}


No comments:

Post a Comment