Try something like this.
The Guest OS is rebooted at the end.
$ExtraValues = @{ "tools.syncTime"=0;
"time.synchronize.continue"=0;
"time.synchronize.restore"=0;
"time.synchronize.resume.disk"=0;
"time.synchronize.shrink"=0;
"time.synchronize.tools.startup"=0;
"time.synchronize.tools.enable"=0;
"time.synchronize.resume.host"=0
}
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$ExtraValues.GetEnumerator() | %{
$extra = New-Object VMware.Vim.optionvalue
$extra.Key=$_.Key
$extra.Value=$_.Value
$vmConfigSpec.extraconfig += $extra
}
$vmConfigSpec.ScheduledHardwareUpgradeInfo = New-Object -TypeName VMware.Vim.ScheduledHardwareUpgradeInfo
$vmConfigSpec.ScheduledHardwareUpgradeInfo.UpgradePolicy = “always”
$vmConfigSpec.ScheduledHardwareUpgradeInfo.VersionKey = “vmx-13”
Get-Datacenter -name Testing | Get-Folder -name "Testing" |
Get-Vm -PipelineVariable vm |
ForEach-Object -Process {
# Script 2
if($vm.ExtensionData.Guest.ToolsVersionStatus2 -eq [VMware.Vim.VirtualMachineToolsVersionStatus]::guestToolsNeedUpgrade){
Update-Tools -NoReboot -VM $vm
}
# Script 1 + 3
$vm.ExtensionData.ReconfigVM($vmConfigSpec)
Restart-VMGuest -VM $vm -Confirm:$false
}