Change virtual machines network adapter using PowerCLI
A few times in my network I had to change the virtual adapter for over 500 VMs. Because a manual configuration of those VMs was not a solution, I turned to PowerCLI. To start open you PowerCLI console and connect to your vCenter Server.
One way of doing this:
$vm = get-vm $newnet = "VM Network - 192.168.100.x" get-vm $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $newnet -Confirm:$false
In this example the script will change the network adapter for all the VMs that resides in your vCenter Infrastrucutre. The $vm = get-vm command reads all the VMs in the infrastrucutre and puts them in a variable. The $newnet = “VM Network – 192.168.100.x” puts the new network adapter in a variable. The last line get-vm $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $newnet assigns the new network adapter to all the VMs in the variable $vm.
Off course you can be more granular and change the network only to the VMs that resides on one, or a couple of ESX Servers, not the entire infrastructure.
$vm = Get-VMHost esx9.vkernel.local | Get-VM
Another way of doing this:
$oldnet = "VM Network-172.x" $newnet = "VM Network-192.x" Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $oldnet } |Set-NetworkAdapter -NetworkName $newnet -Confirm:$false
This script will change the network adapter to all the VMs in your vCenter infrastructure that are connected to VM Network-172.x.
Want content like this delivered right to your
email inbox?
can anyone help me the commands with add an existing VM (on esxi)to network ? and how to find the network info of esxi?
Great informative post. Many thanks