Guide: Dude where’s my vCenter

I’m going to make this a quick one today due to holidays and such, one of my colleagues was pondering the problem of locating the virtual center server when the virtual center application ceases functioning. In a load balanced cluster the virtual center server could be anywhere. He also came up with a pretty cool idea for finding it.

I’ve messed with it a little bit to add some bits and pieces like the AD lookup, I also created a modified version that sends the information back to Nagios so that in the event of a vCenter outage I know which ESX host it is on. I’m happy to share the Nagios version if you send me an email.

# I don't know dude, where is your vCenter?
param (
  [string]$esxPattern = "",
  [string]$esxUsername = "",
  [string]$esxPassword = ""

Add-PSSnapin VMware.VimAutomation.Core

[array]$esxServers = ([adsisearcher]"(&(objectcategory=computer)(name=$esxPattern))").findall() | foreach-object {([adsi]$_.path).name}
[string]$vscHostname = hostname
$vscHostname = $vscHostname.ToLower()

disconnect-viserver * -confirm:$false
connect-viserver -server $esxServers -user "$esxUsername" -password "$esxPassword" -WarningAction SilentlyContinue
$esxHost = (Get-Vm $vscHostname | ?{$_.networkadapters -like "*"}).VMHost

if (!([string]::IsNullOrEmpty($esxHost))) {
  echo "$vscHostname found on $esxHost"
} else {
  echo "Something bad happened and I can't find the virtual center server."

Basically the script will search AD for any computer objects that match the pattern specified in an attempt to find all of the esx servers. It will then connect to all of the servers it finds in AD and look for the host that the script is running on. You need to supply the search pattern for finding the ESX servers as well as the username and the password for logging in as arguments to the script in order for it to work.

Now the astute among you might have noticed the weird looking for network adapters part, this is purely for the benefit of those who have the (mis?)fortune of working with SRM.

Hope you are enjoying the holidays!

comments powered by Disqus