Powershell to get all MAC addresses of each virtual machine on a host and export to tab delimited file

This will spit out the MAC address and name of each virtual machine on a host to a text file. You can then clean the file up and throw it in Excel. I had to use this to clean up duplicate MACs in two different clusters because I’m a bad sys admin and didn’t change the MAC address pools on the hosts or SCVMM.

Get-VM|Get-VMNetworkAdapter | Select-Object VMName, MACAddress | Export-Csv -delimiter “`t” -path C:\macs.txt

It comes out looking like this and I just use a find and replace to remove all the ” so I can throw it in Excel. Then I use Excel to find and sort duplicates.

#TYPE Selected.Microsoft.HyperV.PowerShell.VMNetworkAdapter
“VMName” “MacAddress”
“server01” “00155D0167E2”
“server02” “00155D0A65E1”

After you paste it into Excel you can use Conditional Formatting > Highlight Cell Rules > Duplicate Values. Then sort by the column with MAC addresses A>Z and look for the highlighted rows.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.