10 October 2014

How to find duplicate MAC addresses in SCVMM 2012 R2

Sometimes, when you move virtual machine from one host to another you can run into duplicate MAC address problem. Of course you can have other scenarios for that situation to happen, for example two hyper-v hosts sharing the same MAC address range etc.

If you have searched for solutions on the internet, you won’t be happy with them. At least I wasn’t. Because I didn’t see the VM name in the results.

So I invested some time and came up with that PowerShell script:

cls
Import-Module virtualmachinemanager
"Working..."
$result = Get-VM | foreach {
foreach ($nic in $_.VirtualNetworkAdapters) {
    $obj = new-object psobject
    $obj | add-member noteproperty Host ($_.Name)
    $obj | add-member noteproperty Type ($nic.MACAddressType)
    $obj | add-member noteproperty MAC ($nic.MACAddress)
    $obj
    }
}
"Done"
$result | sort MAC | ConvertTo-Csv -Delimiter `t -NoTypeInformation | clip

This will get all VM-s, go through each of them and display each virtual network adapters MAC address with the server name. This script will place the results in clipboard for easy pasting and analyzing in Excel.

image