Avatar of jmachado81
jmachado81

asked on 

Update VMware Tools on Windows at powercycle in Powershell

Is there a way to change all windows VMs to upgrade VMware Tools at power cycle?  This is a great site that shows how to change it for ALL VMs, but i just want to do the Windows from guestID or guestFamily.  We have alot of appliances and non-windows systems where the guest manages the tools.

http://www.baylyparker.com/2017/01/powercli-script-for-time-vmtools/ 

#Auto Update VMware Tools on power cycle on an individual VM
$VM = Get-VM $VMName | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$VM.ReconfigVM($vmConfigSpec)
======================================================================
#Auto Update VMware Tools on power cycle for ALL VMs
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-View -ViewType VirtualMachine | % {$_.ReconfigVM($vmConfigSpec) }

#or
Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}
=======================================================================
#To get the current policy
Get-View -ViewType virtualmachine | select name,@{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } }
=======================================================================

Open in new window

Powershell* PowerCLIWindows OSVMware

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon