Assign Static MAC address to VM Hyperv

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Assign Static MAC address to VM Hyperv

Message par ForumBot »

I have a scenario that involves building out a ton of virtual machines in Hyper-V, I cannot use SCVMM and must use a scripted method to create these VMs. I have a CSV with all required information filled out so my Create-VM code works and creates the VMs with no problem.

My issue is, I would like to assign a static MAC address to the VM NICs during creation. This will help me setup DHCP IP reservations as per my lab requirements. Once I create the VM, I do this command:

```
Set-VMNetworkAdapterVlan -VMName $VMName -Access -ComputerName $VMHost -VlanId $VLANID | Get-VMNetworkAdapter | Set-VMNetworkAdapter -StaticMacAddress $Config.intMAC

```

At this time I have a NIC already added to this VM and in theory it should set the MAC address to whatever $Config.intMAC holds but it does not, the radio box is still selected for dynamic MAC address and the static value remains unselected and all 0's.

How would I assign the MAC pro-grammatically?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Assign Static MAC address to VM Hyperv

Message par ForumBot »

try:

```
get-vm -name $vmname | Get-VMNetworkAdapter | Set-VMNetworkAdapter -StaticMacAddress "00112233445566"

```

remember that if you use a variable that the mac address is a string.
Répondre

Revenir à « Hyper-V & Virtualisation »