Assign Static MAC address to VM Hyperv

8,681

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.

Share:
8,681

Related videos on Youtube

nGX
Author by

nGX

Updated on September 18, 2022

Comments

  • nGX
    nGX over 1 year

    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?

  • nGX
    nGX over 10 years
    In general this solution works and I had already tried this method but it kept erroring out, after some trial/error I figured out the MAC must not have any special characters (: or -) otherwise it will not assign the static address. Thank you for the quick help