Random Post: VCAP-DCD Round-Up
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  •  

    PowerCLI – Gather Virtual Machine Network Information

    Mapping the virtual networking can be troublesome at times.  How often are you asked to provide MAC addresses to determine what switch port a Virtual Machine is using?  This quick PowerCLI script will walk through and display the VM name, Port Group(s), IP(s) and MAC Address.

    (get-vm) | %{
      $vm = $_
      echo $vm.name----
      $vm.Guest.Nics | %{
        $vminfo = $_
        echo $vminfo.NetworkName $vminfo.IPAddress $vminfo.MacAddress
    
      }
    }
    

    In this example, %{ } will conduct a foreach on each virtual machine from get-vm, and then a foreach on each virtual network adapter assigned to the VM.

    4 responses to “PowerCLI – Gather Virtual Machine Network Information”

    1. Any tips on how you would do this for a machine that is powered off and doesn’t have a guest operating system installed yet? The VirtualMachine.Guest attribute only seems to have data when the VM is powered on and has the guest tools installed.

    2. I’m actually using the VSphere SDK for .NET but I find the PowerShell examples to be the easiest to translate to C#. I was able to solve my problem by iterating the VM.Config.Hardware.Device collection looking for an instance that is a subclass of VirtualEthernetCard. From there I was able to access the MACAddress property.

    3. Xeleema says:

      So….that last “echo” statement of yours….that’s not rendering correctly.
      it should be ” echo “`n” ” and not “echo "`n"”

    Leave a Reply

    Your email address will not be published. Required fields are marked *