vmtools update on power cycle

So recently I had to powerdown a vast majority of my guests due to an outage.
I thought it a good time to upgrade the vmtools. But bugger me if I was going to edit the settings on every single vm, so I searched for a better way.

Work through vcenter and configure every vm that meets the OS Windows Guest to upgrade vmtools on powercycle

Once again you may need to sign these scripts in order to run them.

I strongly suggest doing the Add-Signature.ps1

Foreach ($v in (get-vm)) {
$vm = $v | Get-View | Where-Object {$_.Guest.GuestFamily -eq 'windowsGuest'}
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "upgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}


Once complete and a powercycle has been done you can set back to manual with this.


Foreach ($v in (get-vm)) {
$vm = $v | Get-View | Where-Object {$_.Guest.GuestFamily -eq 'windowsGuest'}
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}

Stolen from..
http://damiankarlson.com/2011/01/23/managing-vmware-tools-advanced-options-powercli/

So now we can use the knowledge in this code to do some really simple cool things….

Start every vm that meets the OS family Windows Guest

Foreach ($v in (get-vm)) {
$vm = $v | Get-View | Where-Object {$_.Guest.GuestFamily -eq 'windowsGuest'}
Start-VM -VM $vm</code>

Advertisements