RobbertE
Contributor
Contributor

Script to change VMXNET3 MacAddress type to Static with current Mac

Hi!

The inevitable has happend, I have to work with PowerCLI. ANd my gosh, this is Powerful! But still, new to all this and looking for a specific solution:

I need to change the Mac address to static on all VMXNET3 network adapters, whilst retaining the current MAC address. So, in functional Language

For all VMNICs in all WIndows Virtual Machines:

Get current MAC address

Set addresstype = static

Set MAC address = current MAC Addres

Then the changes in VMX msut get to vCenter:

"vim-cmd /vmsvc/reload /vmfs/volumes/<Datastore>/<pathtoVM>/VM.vmx"

Is this all possible with ESX / vCenter 4.1.U1 and WIndows 2008 R2 Sp1?

Many thanks!

0 Kudos
2 Replies
alanrenouf
VMware Employee
VMware Employee

You cant actually use a MAC address which is assigned by vCenter as a static MAC address, there is a different range set aside for the manual mac addresses which must start with 00:50:56, more information on this can be found here: http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&e...

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
mattboren
Expert
Expert

Hello, RobbertE-

Yes, PowerCLI (and PowerShell) -- powerful indeed, as the names imply.

Setting the MAC address for a NIC is mostly straightforward.  We recently wrote about it a bit ago at vNugglets.com.  See the Setting MAC Address for VM NICs using PowerShell post from a couple of months ago.

The code there will set the MAC address type to static and set the MAC address to the desired value.  This handles updating the VMX -- no further interaction should be needed.

And, btw, if you wanted to get the VM's current MAC address first, you can use:

Get-VM myVM | Get-NetworkAdapter

Enjoy

0 Kudos