Site icon Grzegorz Kulikowski

Change vnic type from / to e1000, Flexible, Vmxnet, EnhancedVmxnet, and Vmxnet3, and Unknown with Set-NetworkAdapter. UPDATED!

What if you noticed that your vms are running on wrong network card type ? Let’s say you want e1000 instead of vmxnet3 for some reason.There is a great cmdlet set-networkadapter. This will help us out in that kind of situation(Thx Rafael!).
Right, so what set-networkadapter can do for us ? (by this time you should read the get-help set-networkadapter -full). So now, like you already know 😉 it can do a lot for us! But what i want from it right now, is to help me with changing the adapter type. I want to change it from vmxnet 3 to e1000, would be cool if i will not need to shutdown vm too 😉 Unfortunately it will not be so cool at all !!! VM has to be powered off to make this change properly. Please do not do this while vm is up and running.

[sourcecode language=”powershell”]
get-vm ‘myvm’|get-networkadapter|set-networkadapter -type e1000
[/sourcecode]
It’s done. Wooohoooo ! so quick ! so nice ! ok, what why when etc 😉
As per description for the cmdlet:

DESCRIPTION
Changes the configuration of the virtual network adapter. You can change the MAC address and the network name, and to configure the Connected, StartConnected, and WakeOnLan properties of the adap
ter.

Now, how the cmdlet works. It can take input from pipeline, it can take parameters. The required parameter is called NetworkAdapter, and it is expected to be a NetworkAdapter type.
So we first have to deliver somehow the networkadapter that we want to manipulate to set-networkadapter. Get-networkadapter (see the verb?get…set…;) ) will deliver us this.
If you will do get-networkadapter you will receive all network adapters for a vm. If you want to change network adapter for particular network card you will have to select proper network adapter before passing this to set-networkadapter.
[sourcecode language=”powershell”]
get-vm ‘vm_name’|Get-NetworkAdapter|? {$_. MY PROPERTY -eq/-like sth} | let set-networkadapter do stuff
[/sourcecode]
So how can you filter those networkadapters. The easiest way to check this is to see what are the properties that you can filter.
[sourcecode language=”powershell”]
get-vm ‘vm_name’|Get-NetworkAdapter |select -first 1 | fl *

MacAddress
WakeOnLanEnabled
NetworkName
Type
ParentId
Parent
Uid
ConnectionState
ExtensionData
Id
Name
[/sourcecode]

I know that i want to change the networkadapter for card connected to portgroup non-prod.
[sourcecode language=”powershell”]
get-vm ‘your_vm’|Get-NetworkAdapter |?{$_.NetworkName -like "Non-P*"}
[/sourcecode]
Property NetworkName is the portgroup name. the $_. is the current object i the pipeline. So i am checking currect network adapter’s networkname property to see if it is like non-p* . I want all network interfaces that are non-production to be changed to vmxnet3/e1000.
[sourcecode language=”powershell”]
get-vm ‘your_vm’|Get-NetworkAdapter |?{$_.NetworkName -like "Non-P*"} | set-networkadapter -type vmxnet3
or
get-vm ‘your_vm’|Get-NetworkAdapter |?{$_.NetworkName -like "Non-P*"} | set-networkadapter -type e1000
[/sourcecode]
While executing this you will be asked if you really want to do this 😉 If you are confident about network adapters which you will be changing you can add : “-confirm:$false” to the set-networkadapter , and the question will no longer appear.
I have tested this on windows vms and linux vms.(Apparently i have tested it and did not spot things which daveb did, thx !). You can change those network card types while vm is powered on. What is most important, MAC address is not changed. No reconfiguration is needed on the O/S side. And wrong again ;( When the vm nic had network information on it, and you have shut down vm and used set-networkadapter to change the nic type, the card will loose all ip config in windows. The only thing that will remain is the MAC. MAC will not be changed.
@09.11.12 updated – typos (Thx KB)
@19.11.12 updated – not enough testing (Thx daveb)
@20.11.12 update – Problem was mentioned on communities, VMware will update documentation for this cmdlet.[LINK]