You dont have javascript enabled! Please enable it!

How to Set Dynamic MAC Address On a Hyper-V VM with PowerShell

3 Min. Read


Since Hyper-V’s inception back in 2008, you can configure a virtual machine to use a dynamic or a static MAC address for any given virtual network adapter.

Hyper-V by default uses a dynamic MAC address – which means that Hyper-V will generate an initial MAC address for each network adapter, either for VM (vmNIC) or for the host (vNIC), and it will regenerate the MAC address if it believes it is necessary.

If you use static MAC addresses, you can use the MAC address that was generated initially for you, or you can manually specify the MAC address to use, but once a static MAC address is set on a VM, Hyper-V will never change it.

Each Hyper-V server has a MAC address range that it uses for generating new dynamic MAC addresses. You can also configure this range yourself if you want to. Each Hyper-V host generates a default pool. They all use the same first three octets: (00-15-5D), as Microsoft owns that prefix. The next 2 octets (14-22) are generated by the last two octets of the IP address that was first set up on the Hyper-V server. The last octet (FF) is generated from the range 0x00xFF.

How to Set Dynamic MAC Address On a Hyper-V VM with PowerShell 1

I was working recently on a scenario where I want to change the default MAC address pool on each Hyper-V host, and then I want to force all virtual machines to get a new MAC address from the new pool. The challenge is, all virtual machines are already set to use a static MAC address.

How to Set Dynamic MAC Address On a Hyper-V VM with PowerShell 2

To generate a new MAC address for the VM which is set to use a static MAC address, you want to go through the following steps:

1) Shut down the VM if it’s running.

2) Set the VM to use a dynamic MAC address. You can do this via Windows Admin Center, Hyper-V Manager, or using PowerShell (script below).

3) Turn On the VM. Hyper-V will then generate a new Dynamic MAC address from the newly defined pool range.

4) If you want to set back static MAC address, then you can do this via Windows Admin Center, Hyper-V Manager, or using Set-VMNetworkAdapter PowerShell cmdlet.

What if you have a lot of VMs? PowerShell to the rescue!

Set Dynamic MAC address ⌨

If you want to set a static MAC address on a Hyper-V VM using PowerShell, then you can do this with a single command as follows:

Set-VMNetworkAdapter -VMName SRV-VM01 -StaticMacAddress "00155D62F44C"

However, Set-VMNetworkAdapter with -DynamicMacAddress parameter won’t work as you expect to set a Dynamic MAC address. For this, we need to leverage WMI and root\virtualization\v2 namespace.

Here is a PowerShell script that will do the job for you. You can develop around it and target a large number of VMs:

 A script is used to set Dynamic MAC Address.

 A script is used to set Dynamic MAC Address on a single Hyper-V VM.

 Created   : 17-12-2019
 Version   : 1.0
 OS        : Windows Server 2016 Hyper-V or later
 Requires  : PowerShell 5.1
 Author    : Charbel Nemnom
 Twitter   : @CharbelNemnom
 Disclaimer: This script is provided "AS IS" with no warranties.

 To provide feedback or for further assistance please visit:
.\Set-VMDynamicMACAddress -HostName <HyperV-HostName> -VMName <VMNAME> -Verbose 
[Parameter(Position = 0, Mandatory = $true, HelpMessage = 'Enter the Hyper-V Host Name')]

[Parameter(Position = 1, Mandatory = $true, HelpMessage = 'Enter the VM Name')]

Invoke-Command -ComputerName $HostName -ScriptBlock {
Param ($VMName)

$adapter = Get-VMNetworkAdapter -VMName $VMName
$VerbosePreference = "continue"

Write-Verbose "Checking if VM: $VMName is set to use Dynamic MAC Address..."
$Msvm_VirtualSystemManagementService = Microsoft.PowerShell.Management\Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService
$wmiPortSettingData = Microsoft.PowerShell.Management\Get-WmiObject -Namespace root\virtualization\v2 -Class "Msvm_SyntheticEthernetPortSettingData" | Where-Object {$_.instanceID -eq $}

if ($wmiPortSettingData.StaticMacAddress -eq $true) {
if ($adapter.Status) {
Write-Verbose "Stop the VM: $VMName"
Stop-VM -Name $VMName -Force | Out-Null
$wmiPortSettingData.StaticMacAddress = $false
$wmiPortSettingData.Address = ""
$result = $Msvm_VirtualSystemManagementService.ModifyResourceSettings($wmiPortSettingData.GetText(2))
Write-Verbose "Dynamic MAC Address is set on VM: $VMName"
else {
Write-Verbose "The VM: $VMName is already set to use Dynamic MAC Address..."

if (!$adapter.Status) {
Write-Verbose "Start the VM: $VMName"
Start-VM -Name $VMName | Out-Null

} -ArgumentList $VMName

Here is the output when you run the script:

How to Set Dynamic MAC Address On a Hyper-V VM with PowerShell 3

If you have any feedback or changes that everyone should receive, please feel free to leave a comment below.

That’s it there you have it.

Learn more 📕

Do you want to learn about Windows Server Hyper-V, I highly encourage you to check Windows Server 2016 Hyper-V Cookbook for in-depth details about Hyper-V and automation tasks.

Thank you for reading my blog.

If you have any questions or feedback, please leave a comment.

-Charbel Nemnom-

Photo of author
About the Author
Charbel Nemnom
Charbel Nemnom is a Senior Cloud Architect, Swiss Certified ICT Security Expert, Certified Cloud Security Professional (CCSP), Certified Information Security Manager (CISM), Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT). He has over 20 years of broad IT experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems with extensive practical knowledge of complex systems build, network design, business continuity, and cloud security.

Related Posts


Passed Exam AZ-400: Microsoft Certified Azure DevOps Engineer Expert

How To Automate File Restore From Azure File Share Snapshot


4 thoughts on “How to Set Dynamic MAC Address On a Hyper-V VM with PowerShell”

Leave a comment...

  1. Good afternoon, how are you?

    Once again I’m on your blog, which is very rich in information and technical material, I want to congratulate you on the project.

    I have a doubt, in Hyper-V Cluster environments that do not use the SCVMM tool, we have a problem that is common, each Hyper-V host has its Mac Address pool to deliver the virtual machines, it happens that every clean installation of Windows Server and activation of the function the Mac Address range is the same.

    The most common problems that happen:

    A virtual machine named DC1 created on HOST01 receives a mac address generated on host01, performs the live migration to HOST02, the mac that was generated on host01 continues in the virtual machine that is running on Host02.

    If I create a new machine on host01, the mac of this machine that was migrated is available for a new virtual machine and there is a duplicate mac address.

    In this case, in an environment of many Hyper-V hosts in a Cluster without using the SCVMM console, do we have any configuration that we should do so that this mac duplicity problem does not happen in the environment?

  2. Hello Diogo, thanks for the comment and feedback, much appreciated!
    To avoid such cases, Microsoft makes it possible to change the range of dynamic MAC addresses generated by a Hyper-V host.
    Also, this way you can increase the limit of 256 addresses by changing the appropriate octets. This can be done using both, the GUI (Hyper-V Manager) and PowerShell.

    # Change the Minimum and Maximum range of dynamic MAC addresses, use the following command:
    Set-VMHost -MacAddressMinimum 00155DEC6300 -MacAddressMaximum 00155DEC63FF
    # Get the range of dynamic MAC addresses, use the following command:
    Get-VMHost | Select ComputerName, MacAddressMinimum, MacAddressMaximum | ft

    An important point to note here is, if you are going to change the Minimum and Maximum values ​​of dynamic MAC addresses, then make sure the dynamic MAC addresses are NOT within the range of static MAC addresses that you might be using in some VMs.
    Please note that changing the range does not automatically change the MAC address of the already created network adapters. To get the new address, you’ll need to remove them and create them again.
    Hope it helps!

  3. Good night, how are you?

    My dear, thank you very much for your reply!

    A doubt, using SCVMM is it possible to configure the VMM to manage the MAC Address delivery? It happens that if the machine has a dynamic Mac Address, the Hyper-V Host assigns a new MAC, is it possible to configure the VMM to assign the Mac if it is marked as dynamic? In the case of a fixed MAC, the VMM assigns correctly.

  4. Hello Diogo, thanks for your message!
    Yes, if your Hyper-V hosts are onboarded to SCVMM, you can use SCVMM to configure and manage the MAC address delivery.
    I would recommend creating a custom MAC address pool in SCVMM and do not use the default one, or better delete the existing default Hyper-V pool in SCVMM to avoid duplicate MAC address assignments.
    In SCVMM, select Fabric > Networking > MAC Address Pools > Home > Show > Fabric Resources > Create > Create MAC Pool.
    In the Create MAC Address Pool Wizard, Name and Host Group enter a name and description.
    Very important: In Host Group select the host groups that should use the pool (you may need to create multiple custom pools and assign them to different hosts).
    In MAC Address Range specify the start and end addresses.
    Check the guidance here on how to enter valid hexadecimal values between 00 and FF.
    Hope it helps!

Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the \'Code Blocks\' in \'Black\' by selecting the Code. Thank You!