Skip navigation
VMware

This Question is Answered (go to answer)

2 "helpful" answers available (6 pts)
1,972 Views 31 Replies Last post: Nov 18, 2011 7:24 PM by NolaNick RSS
1 2 3 Previous Next
jcouch Novice 27 posts since
Jun 17, 2009
Currently Being Moderated

Aug 23, 2010 12:35 PM

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?

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
1. Aug 23, 2010 12:53 PM in response to: jcouch
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

I would do that this way


$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

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

 

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
elitekato Novice 3 posts since
Oct 20, 2006
Currently Being Moderated
3. Aug 31, 2010 11:42 AM in response to: jcouch
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Please kindly explain how I can apply this script to all VMs then I would be very appreciated.

Never managed using script before.

Thank you.

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
4. Aug 31, 2010 12:36 PM in response to: elitekato
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

The sample script in my previous answr is against all guests.

The line


Get-View -ViewType VirtualMachine

will retrieve all virtual machines in your vCenter or ESX(i) server

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
elitekato Novice 3 posts since
Oct 20, 2006
Currently Being Moderated
5. Aug 31, 2010 2:48 PM in response to: LucD
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Dear LucD,

Thank you for your reply first of all.

I guess my question is where and how do I apply this script?

I have vCenter 4.1 and 11 ESX 4.1 servers in production cluster.

Putty into each ESX server and runnig this script is all I can think of, but doing it gave me an error message - Bash: Get-View: command not found.

Thank you for your help.

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
6. Aug 31, 2010 3:27 PM in response to: elitekato
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

You run this script from a Windows machine where you have PowerShell and PowerCLI installed.

You use the Connect-VIServer cmdlet to set up the connection  to your vCenter server and then you execute the PowerCLI script from above.

A PowerCLI script doesn't run in the COS of an ESX server but on any Windows client that can connect to your vCenter server.

 

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
elitekato Novice 3 posts since
Oct 20, 2006
Currently Being Moderated
7. Sep 28, 2010 11:14 AM in response to: LucD
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Got it. Make sense to me now.

Thank you very much LucD.

 

Warm regard,

 

 

 

 

 

 

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
9. Sep 27, 2010 1:57 PM in response to: jcouch
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Ok, to query the value you can do


Get-VM | Select Name,@{N="UpgradePolicy";E={$_.Extensiondata.Config.Tools.toolsUpgradePolicy}}

To filter only the guests that do not have manual or UpgradeAtPowercycle you can use the Where-Object cmdlet.

The conditions uses the -notcontains operator.


$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

Get-View -ViewType VirtualMachine | where{"manual","UpgradeAtPowercycle" -notcontains $_.Config.Tools.toolsUpgradePolicy} | %{
   $_.ReconfigVM($vmConfigSpec)
} 

 

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
vmkeef Novice 14 posts since
Jan 18, 2007
Currently Being Moderated
11. Dec 9, 2010 4:38 AM in response to: LucD
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Really nice script ! How could I apply this to a cluster at a time rather than a whole datacenter?

Troy Clavell Guru User Moderators vExpert 14,079 posts since
Oct 12, 2007
Currently Being Moderated
12. Dec 9, 2010 5:03 AM in response to: vmkeef
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs
keithannette wrote:

How could I apply this to a cluster at a time rather than a whole datacenter?

here's what I use


$clusterName = "Cluster1"
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

Get-Cluster -Name $clusterName | Get-VM | %{
     $_.Extensiondata.ReconfigVM($vmConfigSpec)
}

 

vmkeef Novice 14 posts since
Jan 18, 2007
Currently Being Moderated
14. Dec 9, 2010 6:47 AM in response to: Troy Clavell
Re: Need script to enable "Check and upgradetools during power cycling" on all VMs

Thanks Troy, that worked perfectly !!

Bookmarked By (1)

Share This Page

Communities