PowerCLI

 View Only
  • 1.  Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 04:17 PM

    How do I go about sending a query to vcenter and have it output a text file that contains all the mac addresses for all of my vms plus vm name. Any help will be most welcome. thanks



  • 2.  RE: Need a list of MAC addresses for all VMs on vcenter
    Best Answer

    Posted Oct 06, 2011 04:36 PM

    Hello, RadarG-

    You can achieve this pretty quickly with something like:

    Get-View -Viewtype VirtualMachine -Property Name, Config.Hardware.Device | `
       
    Select name,
            @{n
    ="MAC(s)"; e={($_.Config.Hardware.Device | ?{($_ -is [VMware.Vim.VirtualEthernetCard])} | %{$_.MacAddress}) -join ","}} | `
       
    Export-Csv c:\temp\VMMACsInfo.csv -UseCulture -NoTypeInformation

    This basically came from my vNugglets.com post "Find VM by NIC MAC Address with PowerShell -- Fast Like!".  If you are just wanting an ivnventory list of your VMs' MAC addresses, this will do fine.  But, if you are looking for a VM by MAC address, or maybe are looking for duplicates, there are other, easier ways.

    I recently made three (3) MAC address related posts (see them at the MAC Address tag at vNugglets).  There are for finding VMs by MAC address, finding duplicate MAC addresses, and setting MAC addresses on VMs.

    Enjoy.



  • 3.  RE: Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 04:42 PM

    hmm ok so will this output the csv and list both the macs and vm names?

    So I jut log into the vma and connect to my center and run this command.



  • 4.  RE: Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 05:17 PM

    This is powershell, so it requires a windows machine with powershell/powercli installed, not the VMA.



  • 5.  RE: Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 05:45 PM

    Hello, RadarG-

    As, mcowger stated, this is PowerShell code. So, on a Windows machine with PowerShell and PowerCLI installed, you can connect to a vCenter and run that code to get the info.  And, yes, that outputs the VM names and their MAC addresses to a CSV file.



  • 6.  RE: Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 06:47 PM

    If you are using vSphere Distributed Switch:

    1. Select your Distributed Switch
    2. Click on Ports tab
    3. hide all columns and leave these columns: Port ID, Connectee, Runtime MAC address and Port group.
    4. Select your VMs
    5. right click and select "copy to clipboard"
    6. paste it to Excel or Word document.
    7. done!

    :smileywink:



  • 7.  RE: Need a list of MAC addresses for all VMs on vcenter

    Posted Oct 06, 2011 09:35 PM

    RadarG wrote:

    How do I go about sending a query to vcenter and have it output a text file that contains all the mac addresses for all of my vms plus vm name. Any help will be most welcome. thanks

    MUCH easier way, it's graphical and exportable and it's FREE!

    http://robware.net/

    RV Tools, nothing better...