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]
15 comments
Hi Grzegorz,
Great post.
I guess it should be Set-NetworkAdapter instead of set-vmnetworkadapter?
Regards,
KB
Thanks KB, yeah you were right there. I have fixed them 😉 Much appreciated for spotting this.
I tried this and although the adapter type at the VM level changes, it doesn’t change anything in the OS (at least for Win2k8 R2).
A vmxnet3 adapter appears as a 10G interface with a specific name in the OS. When I use this it only changes the adapter type in VM Settings. Logging into the OS still shows a 1G interface with the Intel type (even after an OS bounce).
What I’m cooking up now is a script to do the following:
Identify an adapter by type
Copy that adapters settings to variables
Add an adapter with the copied values (but not connect it)
Remove the old adapter
Connect the new the adapter
reboot the guest OS
Dave
Daveb. you are correct ! i have not noticed this… This is very interesting, windows keeps thinking that this is intel nic, not vmxnet3. Tried to uninstall card, rescan and nothing still the same. Will try to investigate this.
when i used this method vcenter thought it had the new nic / the os didnt, and as soon as it vmotioned to another server it installed the new nic on the OS and I had to re add the IP
After running the script to swap e1000 to vmxnet3, which can be done while the VM is live, you must shut the VM down cold, not reboot, it is the only way to allow windows to see what you have done. Unfortunately this tidbit hurt me in a live environment. I thought the adapters were swapped out but in the guest OS they were not, only in VMware they were swapped. I would like very much if someone has a way to perform the scripted change and restore the original manual IP config. It will revert to DHCP from what I’ve seen, at least 95% of the time, which is very strange.. I would like to understand why 5% of the time the IP is kept.. then again it could be that the adapter in my tests that kept IP were already vmxnet3 adapters… not sure need to test more… but a script that changes this adapter allowing the static IP to remain would score huge in the vmworld…
How about if you just want to change the adpter type on one interface instead of ALL interfaces.
Our VM’s have management, private and public interrface all set to use VMXNET3 but I just want the private interface to be set to E1000? Is that possible or do all three interfaces have to be changed??? I can’t see an option using the Set-NetworkAdapter cmd to just apply it on a single interface.
If you really want to do this, then you have to select the network adapter for ‘set-networkadapter’ cmdlet.
let’s say:
$myvm=get-vm XYZ
$networkcards=get-NetworkAdapter -VM $myvm
in $networkcards you will have now probably 3 nics, mgmt,priv,pub
$thisparticularnic=$networkcards |?{$_.Name -eq ‘that interface name’}
or
$thisparticularnic=$networkcards |?{$_.NetworkName -eq ‘that interface network name’}
$thisparticaularnic should hold only 1 network card at this moment
set-networkadapter -NetworkAdapter $thisparticularnic ….
or shorter
get-vm ‘myvm’|get-networkadapter |?{$_.NetworkName -eq ‘that mgmtcard portgroup’}|set-networkadapter …..
This will pass that mgmt nic to set-networkadapter cmdlet
I tried the shorter version:
get-vm ‘myvm’|get-networkadapter -NetworkName ‘that mgmtcard portgroup’|set-networkadapter …
But the -NetworkName parameters is NOT available with the get-networkadapater command.
http://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Get-NetworkAdapter.html
This has been fixed. When you run the command to set-networkadapter, it prompts you for each interface to see if you want to change the adapter type or not.
Hi, sorry for this, my bad, i did not check for get-networkadapter , but you can still use this like this:
get-vm ‘myvm’|get-networkadapter |?{$_.NetworkName -eq ‘that mgmtcard portgroup’}|set-networkadapter …..
Hi all, I have one question:
I have successfully changed the network adapter. Unfortunately, my Windows Server losing all network settings. I always have to change it manually to the old Settings.
This is very bad if the Server is a DC.
Is there a way to Change the Network Adapter without losing the Network Settings?
Thanks for help!
Martin
When I need to do this I add a new NIC of the required type to the VM, then inside the VM I disable the new NIC and change its setting identical to the NIC it’s replacing. I then disable the original NIC and immediately enable the new NIC. This will disconnect the VM from the network for only a few seconds. Then I can go in and remove the old NIC.
Dear Admin / colleagues, I have about 1000VMs I need to change the nic type from e1000 to vmxnet3. The script above is for individual VMs one-by-one, Is there a way I can
Have the script to check all the VMs, if the Network adapter type = e1000, it should change is to vmxnet3
please don’t run it unless you know what are the results. I believe that you will lose the ip settings inside the o/s if you change a network card type like this.