VMware Cloud Community
jcouch
Enthusiast
Enthusiast
Jump to solution

Need script to enable "Check and upgradetools during power cycling" on all VMs

What is the best method for enabling this option on all VMs? Is there a good way to do it without either editing the VMX files on every machine or doing it manually though edit settings?

Tags (1)
61 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, it should.

Does it not work for you ?


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

Reply
0 Kudos
kgilbert
Contributor
Contributor
Jump to solution

fantastic tip!

thanks dhenry

Reply
0 Kudos
awarnerinpa
Contributor
Contributor
Jump to solution

LucD/All,

Background: Running ESXi 5.5U1 on 30 hosts and 550+ VMs. Maintaining current tools version is next to impossible manually.

Hoping there is a way to make this work. Based off of LucD's script this is what I am currently using:

#Connect to vCenter

$vCenter = Read-Host "Which vCenter do you want to connect to?"

Connect-VIServer $vCenter

#Create variable

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

#Execute change for all VMs excluding templates

Get-View -ViewType VirtualMachine | %{

   $_.ReconfigVM($vmConfigSpec)

}

However, I want to see if there is a way to specify custom installation options with this option as we do not want to install vShield Drivers, Shared Folders, etc. Hoping someone catches this response since the thread has been idle for some time. Thanks for any information you can provide!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Andreas has a good post on that. See An analysis of the vSphere 5.5 VMware Tools for Windows installation

You could script the running of the setup.exe via Invoke-VMScript, or you could update the bat files with your own version, and then use the method I mentioned earlier.


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

Reply
0 Kudos
Afham
Contributor
Contributor
Jump to solution

Hi LucD‌ and everyone!

How can i write script to change vmtools of its upgrade policy during powercycle and only ist of servers on a notepad that i keep on a particular path?


Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry the question is not clear to me.

Perhaps you can elaborate a bit more, and eventually show with some screenshots what you want to achieve ?


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

Reply
0 Kudos
Afham
Contributor
Contributor
Jump to solution

Hi Luc,

i would like the script to call for list of servers that i put on a notepad in a certain path.

Only this list of servers then only i would want it to edit the upgrade policy to upgrade during powercycle.

Could you please help?

Reply
0 Kudos
Afham
Contributor
Contributor
Jump to solution

Hi Luc,

managed to write the powershell like i want like in following,

$vCname = Read-Host “Enter the vCenter or ESXi host name to connect”

if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {

    Add-PSSnapin VMware.VimAutomation.Core

}

Connect-viserver $vcname

$VirtualMachines = Get-Content "upgrade_vmware.txt"

foreach ($vm in (Get-VM -Name $VirtualMachines)){

    if($vm.config.Tools.ToolsUpgradePolicy -ne "UpgradeAtPowerCycle") {

        $config = New-Object VMware.Vim.VirtualMachineConfigSpec

        $config.ChangeVersion = $vm.ExtensionData.Config.ChangeVersion

        $config.Tools = New-Object VMware.Vim.ToolsConfigInfo

        $config.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

        $vm.ExtensionData.ReconfigVM($config)

        Write-Host "Update Tools Policy on $vm completed"

    }

}

Thanks!

Reply
0 Kudos
VSnip
Enthusiast
Enthusiast
Jump to solution

Hello !

Thank you for this script.

I've another question about this:
How can we apply this for Windows Server only and for Windows Server >=  2008  (2008, 2008R2, 2012....)?

We have to make a loop in which you filter, I suppose. ^_^

I don't know how to do. Can you help me? Please

Thank you! 😃

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could use the -match operator, and check if the Guest OS Fullname contains 2008, 2012 or 2016.

Something like this

Get-VM | where{$_.Guest.OSFullName -match "2008|2012|2016"} |

Select Name


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

Reply
0 Kudos
VSnip
Enthusiast
Enthusiast
Jump to solution

Great! I try it.
Thanks for your help.

Have a good day Smiley Happy

Reply
0 Kudos
VSnip
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

What do you think about this 2 scripts? What is the best? 

Get-VM | Where-Object{

$_.Guest.OSFullName -match "2008|2012|2016"

} | ForEach-Object{

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

Get-View -ViewType VirtualMachine | %{$_.ReconfigVM($vmConfigSpec)}

}

Or

Get-VM | Where-Object{

$_.Guest.OSFullName -match "2008|2012|2016"

} | ForEach-Object{

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

(Get-View $_.ID).ReconfigVM($vmConfigSpec)

}

If there is errors, tell me! haha

I prefer to ask you before execute one of the two script. I'm new in scripting. :smileyblush:

Thank you for your help. :smileygrin:

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The first one is wrong, it will do a reconfig for all VMs each time it loops through the outer ForEach loop. Probably not what you want.

On the 2nd one you can save a Get-View by using the ExtensionData property.
And by only constructing the some $vmConfigSpec object once, outside the loop

Like this

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec 

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo 

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

Get-VM | Where-Object{$_.Guest.OSFullName -match "2008|2012|2016"} | ForEach-Object

    $_.ExtensionData.ReconfigVM($vmConfigSpec)

 


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

Reply
0 Kudos
VSnip
Enthusiast
Enthusiast
Jump to solution

It work fine!
Thanks a lot Luc!

Reply
0 Kudos
gelasodun
Contributor
Contributor
Jump to solution

I would like to enable the option in specific vm rather than all VMS  could you please help me for this.

Just i save the vm name in text file and execute the script, then option will enable in those VMS which are in text file.

Reply
0 Kudos
gelasodun
Contributor
Contributor
Jump to solution

Just we save the VMS name in text file or notepad then option will enable in those specific VMS which are in text file or notepad.

I don't want to enable it all the VMS please help me for this sir...

Reply
0 Kudos
gelasodun
Contributor
Contributor
Jump to solution

I have same doubt aflam is saying..

Please send the script and help us.

Just save the VMS name in text or notepad in certain path and execute the script then VMware tool upgrade option will enable those VMS which are saved in text or notepad file.

Please help ...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You would only need to change the last couple of lines into something like this

Get-VM -Name (Get-Content vmnames.txt) | %{

     $_.Extensiondata.ReconfigVM($vmConfigSpec)

}


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

Reply
0 Kudos
Grizzled_1
Contributor
Contributor
Jump to solution

How do I use this to change ToolsUpgradePolicy to VMs from a CSV (get-csv) or TXT (get-content)? I am struggling... 
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My last reply uses a .txt file to select the VMs.


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

Reply
0 Kudos