3

#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

Filed in: Columns, Tips and Tricks Tags: , ,

3 Responses to "#PSTip Get currently available MAC address from Hyper-V MAC address pool"

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: