#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.
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)
Share on: