VMware Cloud Community
JDLangdon
Expert
Expert
Jump to solution

PowerCli Script to Edit VM Options?

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

Reply
0 Kudos
1 Solution

Accepted Solutions
Troy_Clavell
Immortal
Immortal
Jump to solution

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)
}

View solution in original post

Reply
0 Kudos
7 Replies
Troy_Clavell
Immortal
Immortal
Jump to solution

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

Reply
0 Kudos
BilBens
Enthusiast
Enthusiast
Jump to solution

see this link

http://www.vhersey.com/2011/05/vmware-powercli-function-to-modify-virtual-machine-configuration-opti...

Sincerely,

Bil Bens

Please consider the use of the Helpful or correct buttons to award points to those Answers you found useful or correct.
JDLangdon
Expert
Expert
Jump to solution

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.

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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

Reply
0 Kudos
maishsk
Expert
Expert
Jump to solution

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

@maishsk | My Blog

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
JDLangdon
Expert
Expert
Jump to solution

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?

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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)
}

Reply
0 Kudos