VMware Cloud Community
richG
Contributor
Contributor

Is there a way to change your Network Cards with PowerCLI on 1000 Guests

Hi all,

I am trying to figure out if there is a way to perform a major change for all my Guests systems. Vmware has asked us to change all of our VM Guest from Flex and E1000 to VMXNET 3, now this can be done manually, but as I have 944 guest in the enterprise it will take me a while to work through them all.

Ok so here is the problem

The script will have to have to check two things before it does this check for the latest tools, and that the guest is running hardware level 7 as well. If it does not meet any of these reuirements it would have to output the host and guest name to a failed file.

If you change the the Network card you have to re-enter all the network information on the new network adapter. So I would say the first part of the script would have capture all the network settings from the old network card, hold that in a variable.

Add the new Network card and use the informaton in the Variable to the new network card. I would say it would have to reboot the VM..

Then move on to the next guest system.

Now I am not looking to do all 944 at once I would do it in sections like Dev first and then QA.

So if anyone has any suggestions on the best way to go about doing this it would be greatly appreciated.

Regards,

RichG

0 Kudos
6 Replies
LucD
Leadership
Leadership

Provided your guests have only 1 NIC, you can try something like this

$guestUser = "user"
$guestPswd = "password"
$targetToolsVersion = "8295"

$success = @() $fail = @() foreach($vm in Get-VM){     if($vm.Version -eq "v7" -and $vm.Guest.ExtensionData.ToolsVersion -eq $targetToolsVersion){         $nicGuest = Get-VMGuestNetworkInterface -VM $vm -GuestUser $guestUser -GuestPassword $guestPswd         $nic = Get-NetworkAdapter -VM $vm
       
Shutdown-VMGuest -VM $vm -Confirm:$false
        while((Get-VM -Name $vm.Name).PowerState -ne "PoweredOff"){             sleep 5
        }        
Remove-NetworkAdapter -NetworkAdapter $nic -Confirm:$false
       
New-NetworkAdapter -VM $vm -Type Vmxnet3 -Confirm:$false -NetworkName $nic.Networkname         Start-VM -VM $vm -Confirm:$false
       
while((Get-VM -Name $vm.Name).Extensiondata.Guest.ToolsRunningStatus -ne "guestToolsRunning"){             sleep 5
        }        
Get-VMGuestNetworkInterface -VM $vm |         Set-VMGuestNetworkInterface -Dns $nicGuest.Dns -Gateway $nicGuest.DefaultGateway -Ip $nicGuest.Ip `
        -Netmask $nicGuest.SubnetMask -Wins $nicGuest.Wins `
        -Confirm:$false -GuestUser $guestUser -GuestPassword $guestPswd

       
$row = "" | Select VM,Host         $row.VM = $vm.Name         $row.Host = $vm.Host.Name         $success += $row    }     else{         $row = "" | Select VM,Host         $row.VM = $vm.Name         $row.Host = $vm.Host.Name         $fail += $row    } } if($fail){     $fail | Export-Csv "C:\failed-vm.csv" -NoTypeInformation -UseCulture
}

$success
| Export-Csv "C:\success-vm.csv" -NoTypeInformation -UseCulture

Note that the script also assumes that you can use the same account on all VMs to configure the network settings.

You will also have to update the $targetToolsVersion value for your environment.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
richG
Contributor
Contributor

Thank you very much for your help. I have to admit I was praying you might see this thread and reply to it.. I will test this weekend on a few of my dev servers and if all goes to plan then I will let you all know.

Have a good weekend..

RichG

0 Kudos
sketchy00
Hot Shot
Hot Shot

Please let us know how it goes.  I have always taken a pretty conservative approach on NICs, and ended up sticking with E1000 on almost all of my VMs, but I see that especially with newer releases of vsphere, it may be time to make the change.  ...It would be nice to know how, in bulk.

0 Kudos
richG
Contributor
Contributor

Hi well I wanted to give an update on how this project is going, I also have a couple of questions as well

Question first.  -Netmask $guestNic.SubnetMask -Wins $nicGuest.Wins ` this code was it a mistake or intentional for the -netmask $guestNic.SubnetMask. I thought it should be $nicGuest.subnetmask??

As always in a perfect world this script would work like a charm. As I have so many different servers it is proving to be harder then I thought.

The one major problem is this is all running on HP hardware and windows 2003 - 2008R2 the old network card is not remove it is just hiddened. So I have to manually go in and remove it from each VM Guest.

o work around this behavior and display devices when you click Show hidden devices:

Click Start, point to All Programs, point to Accessories, and then click Command Prompt.

At a command prompt, type the following command , and then press ENTER:

set devmgr_show_nonpresent_devices=1

Type the following command a command prompt, and then press ENTER:

start devmgmt.msc

Troubleshoot the devices and drivers in Device Manager.


NOTE: Click Show hidden devices on the View menu in Device Managers before you can see devices that are not connected to the computer.

When you finish troubleshooting, close Device Manager.

Type exit at the command prompt.

This is the process I have to go through each time..

I am getting different errors on different servers. I think I got one with out errors it was nice..

The command I had to add to the scirpt was to turn on the network card on startup. -startconnected

I suggest as it does take a little while to run is to do them in batches, say from a text file like add 1- 20 names and have the script read it from the file, and perform the operation..

Over all the script is great thank you..

0 Kudos
LucD
Leadership
Leadership

Q1: yes, that was a typo, it's corrected now.

Q2: I would look at the possibility to use the 'devcon' command inside your guest OS.

You can call that 'devcon' command with the Invoke-VMScript cmdlet, provided your guest complies with all the requirements for that cmdlet.

See for example How to remove ghost Network Interfaces in Windows 7/2008 to see how the 'devcon' command can be used.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
richG
Contributor
Contributor

Thank you once again for all the help and suggestions. I am looking at them now..

It a slow slug getting through this, but you have made it easier thanks..

Kind regards,

Richard J Garrow MCSE

Sr Systems Engineer

Gartner Loc: Trumbull CT

Office: 203-873-2555

Cell: 203-278-7813

Email: richard.garrow@gartner.com<mailto:richard.garrow@gartner.com>

P Please do not print this e-mail unless you really need to.

0 Kudos