Monday, November 28, 2016

Finding the host where your VM resides

It seems funny but possible, where using virtual vCenter and didn't created any VM-host affinity rule to limit its movement on hosts and in case if vCenter goes down then this script could be useful in locating it....
#Script to find a VM from a pool of individual hosts having differ passwords

Add-PSSnapin VMware.VimAutomation.Core

$connectvmhost = "Connect-VIServer host-A -user root -password xyz"
$connectvmhost += "Connect-VIServer Host-B -user root -password 123xyz"

$connectvmhost

Get-VM vm-name -server Host-A, Host-B | select Name, VMhost

Disconnect-VIServer -Confirm:$false

If all hosts are having the same password, then,
$usr = 'user_name'
$pwd = 'password'

$connectvmhost = "Connect-VIServer host-A -user $usr -password $pwd"
$connectvmhost += "Connect-VIServer Host-B -user $usr -password $pwd"

$connectvmhost

Get-VM vm-name -server Host-A, Host-B | select Name, VMhost

Disconnect-VIServer -Confirm:$false

I believe, there would be a better way to do this but this also serves the purpose.

That's it... :)


No comments:

Post a Comment