Thursday, February 2, 2012

Find a VM without vCenter

This probably doesn't happen too often, but it did to a friend of mine - vCenter was down and he needed to find the ESX host where the supporting SQL server was registered so he could start it and troubleshoot if needed.

Putting aside why this happened and how it could have been prevented, we just needed to fix it quickly.  So, I put on my PowerCLI hat and pounded out the following....

$findvm = Read-Host -Prompt "Missing VM Name" 
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Confirm:$false 
$esxservers = get-content "c:\esxiplist.txt" 
Connect-VIServer -Server $esxservers 
$vmlist = (Get-VM | select -expandproperty name) 
foreach ($vm in $vmlist) 
    { 
    if ($vm -eq $findvm) 
        { Write-Host "$findvm was located on $esxserver" exit } 
    } 
Write-Host "$findvm was not located on any host"

The file esxiplist.txt contained the IP addresses for each host (one per line).  This could be made a lot prettier but for our purposes worked well enough to locate the SQL server plus another handful of critical VMs which were also down.  This script assumes that your login credentials are the same for each ESX host.

No comments:

Post a Comment

Post a Comment