Is there a way to use PowerCli to edit the options of a VM? More specifically, I'd like to a PowerCli script to select the check boxes on a VM under the Options --> VMware Tools --> Advanced Settings so the that VMware Tools are upgraded during power cycle and time is sync'd.
Thanks,
JD
here's what we use if you want to pull from a text file.
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
#$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-Content -Path "C:\names.txt" | %{
(get-vm -Name $_).Extensiondata.ReconfigVM($vmConfigSpec)
}
for all guests in vCenter you can do something like for the "check and upgrade tools at power cycle"
get-vm | foreach-object {
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
#$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
(Get-View $_.ID).ReconfigVM($vmConfigSpec)}
Just so you know... there is a bug where anything Windows 2003 and below, will not work unless the reboot is done through and RDP session or while logged into the guest console. We have a PR open
see this link
Sincerely,
Bil Bens
I'm using LANDesk to restart the VM's which appears to work fine. I'm guessing it is because the reboot is still orginiating inside the guest os.
good news. You want your guests time to sync with ESX? We sync ours with AD. We use a script to do that, you can reverse engineer it if you'd like.
$Service = "W32Time"
$arrComputer = Get-Content("c:\pclist.txt")
foreach($strComputer in $arrComputer)
{
Get-VM -Name $strComputer | % { Get-View $_.ID} | `
% {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo
$spec.tools.syncTimeWithHost = $false
Get-View($_.ReconfigVM_Task($spec))
}
Get-Service W32Time
$time = Get-WmiObject win32_service -ComputerName $strComputer | where-object {$_.Name -eq "W32Time"}
$time.ChangeStartMode("automatic")
$status = (Get-Service -Name $Service -ComputerName $strComputer)
if($status.status -eq "stopped")
{
($status).start()
}
}
This script uncheck's the "Synchronize guest time with host" then starts the windows time service in the guest OS
I actually just wrote a function to update this exact setting yesterday.
Set-UpdateToolsPolicy–For your VM’s
Maish
VMTN Moderator | vExpert
Author of VMware vSphere Design
Ok. Last question, I think.
How do I use this script with a text file containing a list of VM's that I want to make the modifications to?
here's what we use if you want to pull from a text file.
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
#$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-Content -Path "C:\names.txt" | %{
(get-vm -Name $_).Extensiondata.ReconfigVM($vmConfigSpec)
}