I want to check the box "Automating Upgrade of VMware Tools" for all windows VM created in last 7 days. Currenlt , i have following script from which i was providing manual VM name but i need to automate it only for windows VM
foreach($vmlist in (Get-Content -Path C:\TEMP\vmliste.txt))
{
$vm = Get-VM -Name $vmlist
# $VM = Get-VM # Filter here if needed
$VMView = $VM | Get-View
if($VMview.config.tools.toolsUpgradePolicy -ne "upgradeAtPowerCycle")
{
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.changeVersion = $VM.ExtensionData.Config.ChangeVersion
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.ToolsUpgradePolicy = "upgradeAtPowerCycle"
$_this = Get-View -Id $VM.Id
$_this.ReconfigVM_Task($spec)
Write-Host "Update Tools Policy on $vm completed"
}
else
{
Write-Host "Update Tools Policy on $vm already esxists"
}
}
VimException,Microsoft.PowerShell.Commands.ForEachObjectCommand
Exception calling "ReconfigVM_Task" with "1" argument(s): "The method is disabled by 'horizon.daas'"
You didn't mention there were some Horizon View stations in there.
Horizon disables that method since it wants to control the stations it manages.
The best way to upgrade those is to use the Horizon functionality.
Make a new Master or a Snapshot with the correct HW version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi @LucD ,
Is there a way to filter out VM's Horizon View Station VM's in the code itself, so it won't execute on those VM's.
Thanks
If you have the VMware.HV.Helper module, you can use that to retrieve all Horizon VMs.
With the help of such a list you can exclude those VMs.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference