Thursday, December 15, 2011

PowerCLI command to enumerate VM’s mac address inside of vCenter

I did not write this, I found it online but lost the link, but it works great!
ForEach ($VirtualMachine in $VM) {
    # Get the virtual machine
    $VMsView = Get-View -ViewType VirtualMachine -Property Name,Guest.Net -Filter @{"Name"="$VirtualMachine$"}
    if ($VMsView) {
      $VMsView | `
        ForEach-Object {
          $VMview = $_
          $VMView.Guest.Net | `
            Select-Object -property @{N="VM";E={$VMView.Name}},
              MacAddress,
              IpAddress,
              Connected
        }
    }
}

Trying to find a machine on a HP VirtConnect blade by Mac address

 

->show interconnect enc0:*
Displays interconnect modules in all bays of a specific enclosure

->show interconnect-mac-table enc0:1
Displays the module MAC table for the module in bay 1 of enclosure enc0

The resulting output seems to be far too much info, with no way to sort through it.  I just had putty output to a .txt file and then searched it for the mac address in question.

 

d15    00:50:56:3B:0D:2B  Learned  4            -- --  

d5     00:0C:29:73:6C:11  Learned  5            -- --

(lag)  00:50:56:3B:07:91  Learned  4            26    

 
d7     00:50:56:8D:00:00  Learned  4            -- --

 

The ‘d’ number on the left tells you which blade the VM lives on.