VMware Cloud Community
RadarG
Enthusiast
Enthusiast
Jump to solution

Need a list of MAC addresses for all VMs on vcenter

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

1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

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.

View solution in original post

6 Replies
mattboren
Expert
Expert
Jump to solution

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.

RadarG
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
mcowger
Immortal
Immortal
Jump to solution

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

--Matt VCDX #52 blog.cowger.us
Reply
0 Kudos
mattboren
Expert
Expert
Jump to solution

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.

Reply
0 Kudos
MagnetBoy
Enthusiast
Enthusiast
Jump to solution

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!

Smiley Wink

VMware Certified Professional – Datacenter Virtualization (vSphere 5)
RParker
Immortal
Immortal
Jump to solution

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...