#PSTip Get currently available MAC address from Hyper-V MAC address pool

I have written scripts to automate VM deployments across a farm of Hyper-V servers and I prefer using static MAC addresses for all my workload virtual machines. So, it is important for me to find the available MAC address so that I can start incrementing from there.

The Msvm_VirtualSystemManagementServiceSettingData WMI class in the root\Virtualization\v2 namespace gives the maximum and minimum MAC addresses within the pool.

mac

However, the currently available MAC address is not given by this class. For this, we need to look into the Registry on the Hyper-V host at HKLM\Software\Microsoft\Windows NT\CurrentVersion\Virtualization\Worker. The CurrentMacAddress value provides the MAC address that can be assigned to a VM.

$Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Worker'
$CurrentAddress = Get-ItemProperty -Path $Path -Name CurrentMacAddress
[System.BitConverter]::ToString($CurrentAddress.CurrentMacAddress)

mac2

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts

%d bloggers like this: