5

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?

5

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.

  • 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 – KPS Sep 4 '13 at 2:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.