VMware Cloud Community
rGunnal
Contributor
Contributor

Script to upgrade Multiple VM's VMtools

Hi All,

Is there any script where i can upgrade multiple VMs VMtools  ,

like i will show the VM names in text file and VMtools exe file in a location.

Thanks in Advance.

Tags (1)
0 Kudos
28 Replies
LucD
Leadership
Leadership

VMtools.exe?
What do you mean by that?
Do these VMs have guest managed VMware Tools?


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

0 Kudos
LucD
Leadership
Leadership

Does this not work for you?

$vmNames = Get-Content -Path C:\Temp\vmNames.txt

Get-VM -Name $vmNames |  Update-Tools -NoReboot -RunAsync


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

0 Kudos
rGunnal
Contributor
Contributor

This are Windows server and running with 10.0 version, i want to upgrade them to 10.3 later version.

instead of VM Edit settings-> Guest->Install VM tools and loggin each server and running the mounted tools.

i have latest VMtools exe file.. or any script which can pick this exe or else..anyother option VMs get updated with latest vmtools.

0 Kudos
LucD
Leadership
Leadership

The code I shared will not require you to logon to each server.
Did you try it?


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

0 Kudos
rGunnal
Contributor
Contributor

do i need to mount the ISO (edit VM setting, Guest- install VMtools)?

0 Kudos
LucD
Leadership
Leadership

No, normally not.
The Update-Tools cmdlet takes care of that.


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

0 Kudos
rGunnal
Contributor
Contributor

Hi LuCD,

its not working. i ran the script but nothing seems to be happening on VM. even i tried to do reboot.. still it has same older VMtools versoin.

$vmNames = Get-Content -Path C:\Temp\vmNames.txt

Get-VM -Name $vmNames |  Update-Tools -NoReboot -RunAsync

am getting output like this. but nothing seems to be happening in VM OS.

Name                       State  % Complete Start Time   Finish Time
----                       -----  ---------- ----------   -----------
UpgradeTools_Task          Running         0 07:21:29 PM
0 Kudos
LucD
Leadership
Leadership

Do these VMs already have the VMware Tools installed?
Are they Guest Managed versions?


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

0 Kudos
rGunnal
Contributor
Contributor

yes, these VMs have alreday VMware tools running.

i want to upgrade them from 10.2.5.8068406 version to 10.3 version.

0 Kudos
LucD
Leadership
Leadership

And my 2nd question was "Are they Guest Manager tools?"


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

0 Kudos
rGunnal
Contributor
Contributor

LuCD thanks for your response..

am confused when you say "Guest Manager tools"..

it is just VMtools installed on those Vms.

0 Kudos
LucD
Leadership
Leadership

On several OS, mostly Linux, the VMware Tools come as part of the OS.

This is indicated in the Web Client.

guestmanaged.jpg

To upgrade those tools, you will need to use the upgrade features of the guest OS.

Another type of Guest Managed VMware Tools, is when you installed the EXE yourself.
And not through the ISO that comes in vSphere.


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

0 Kudos
rGunnal
Contributor
Contributor

mine is all VMs are Windows. when i see on webclient i get like this.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

That one says version 11, and that it is current.
Did you test on one that says "Upgrade available"?


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

0 Kudos
EricAGoldman
Contributor
Contributor

LucD, I know this is an old post, but I hope you can help me. 

I changed your script slightly and it runs, however, I am trying to add some new 'features'

 

$vmNames = Import-CSV -Path C:\Temp\vmNames.txt

Get-VM -Name $vmNames.'VM Name' |  Update-Tools -NoReboot -RunAsync

 

1. I really like the way it displays the task and % complete on the screen, but how to I create a loop that runs until the last machine in the list is at 100% and can I easily output this file?

2. I have about 800 servers to update and I only want to send 10 servers at a time to be updated. What would be the most efficient way/code to get this done?

 

Thanks!

0 Kudos
LucD
Leadership
Leadership

Are you sure you see a progress bar with the RunAsync switch?


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

0 Kudos
EricAGoldman
Contributor
Contributor

It's not really a progress bar, just information displayed in the Command Screen in Powershell ISE 

 

 

EricAGoldman_0-1627579640218.jpeg

 

0 Kudos
LucD
Leadership
Leadership

Ok, that is the same info you can get with Get-Task.
In fact, you have to use Get-Task, in a loop, till none of the tasks shows "Running" anymore.

Similar when you want to impose a maximum number of background tasks.
With Get-Task you can see how many background tasks are running, and wait if that is equal or more than your desired maximum.


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

0 Kudos
EricAGoldman
Contributor
Contributor

LucD, I have another error that I hope you can help with. The following code works to change the flag to upgradeAtPowerCycle, but it throws an error at the end of the script execution:

<# This will change the Local VM Policy to Update VMTools upon the next reboot#>
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.ToolsUpgradePolicy = "upgradeAtPowerCycle"
$VMs = Import-CSv C:\Temp\MyFile.csv
foreach ($VM in $VMs) {
$VM = Get-VM $VM.VMName | where{$_.Guest.OSFullName -match 'Windows' -and $_.PowerState -eq 'PoweredOn'}
$VM.ExtensionData.ReconfigVM($spec)
}

This produces the following error:

You cannot call a method on a null-valued expression.
At line:7 char:1
+ $VM.ExtensionData.ReconfigVM($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

0 Kudos