What is the best method for enabling this option on all VMs? Is there a good way to do it without either editing the VMX files on every machine or doing it manually though edit settings?
I would do that this way
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle" Get-View -ViewType VirtualMachine | %{ $_.ReconfigVM($vmConfigSpec) }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would do that this way
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle" Get-View -ViewType VirtualMachine | %{ $_.ReconfigVM($vmConfigSpec) }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are the Master LucD! This works great.
Please kindly explain how I can apply this script to all VMs then I would be very appreciated.
Never managed using script before.
Thank you.
The sample script in my previous answr is against all guests.
The line
Get-View -ViewType VirtualMachine
will retrieve all virtual machines in your vCenter or ESX(i) server
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD,
Thank you for your reply first of all.
I guess my question is where and how do I apply this script?
I have vCenter 4.1 and 11 ESX 4.1 servers in production cluster.
Putty into each ESX server and runnig this script is all I can think of, but doing it gave me an error message - Bash: Get-View: command not found.
Thank you for your help.
You run this script from a Windows machine where you have PowerShell and PowerCLI installed.
You use the Connect-VIServer cmdlet to set up the connection to your vCenter server and then you execute the PowerCLI script from above.
A PowerCLI script doesn't run in the COS of an ESX server but on any Windows client that can connect to your vCenter server.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it. Make sense to me now.
Thank you very much LucD.
Warm regard,
Luc,
Powercli Novice here...
I have played around with this script some and have another question for you... How would query for the status of this option?
I want to report on it so I can see which ones need to be change, then I would like to pipe the results of that query to the command so that it only updates the option on those VMs that do not meet the speficied option (manual or UpgradeAtPowercycle).
Thanks!
Ok, to query the value you can do
Get-VM | Select Name,@{N="UpgradePolicy";E={$_.Extensiondata.Config.Tools.toolsUpgradePolicy}}
To filter only the guests that do not have manual or UpgradeAtPowercycle you can use the Where-Object cmdlet.
The conditions uses the -notcontains operator.
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle" Get-View -ViewType VirtualMachine | where{"manual","UpgradeAtPowercycle" -notcontains $_.Config.Tools.toolsUpgradePolicy} | %{ $_.ReconfigVM($vmConfigSpec) }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you! Works great.
Really nice script ! How could I apply this to a cluster at a time rather than a whole datacenter?
How could I apply this to a cluster at a time rather than a whole datacenter?
here's what I use
$clusterName = "Cluster1" $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle" Get-Cluster -Name $clusterName | Get-VM | %{ $_.Extensiondata.ReconfigVM($vmConfigSpec) }
Here is what I did with it after Luc gave me the base code. I needed a way to enable/disable this option for patching time. We noticed it got in the way of windows patching when multiple reboots were required. It will ask you for what cluster and if you want to enable or disable the VMTools options.
==============================================================================================
NAME: ChangeVMToolsOptions.ps1
AUTHOR: Jeff Couch
DATE : 8/23/2010
COMMENT: Base Code author LUCD
==============================================================================================
Connect to Vcenter
$vCenter = Read-Host "Enter vCenter Server name"
Connect-VIServer $vCenter
Determine Options
Write-Host "Name of Cluster: " -nonewline; $Clustername = Read-Host
Write-Host "Enable or Disable Auto Upgrade VM Tools?"
Write-Host "Answer: " -nonewline; $Option = Read-Host
if ($Option -match "Enable"){$status = "UpgradeAtPowerCycle"}
else {$status = "Manual"}
Write-Host "This will $status all vmtools Auto upgrade on the $Clustername."
Write-Host "Are you sure that you want to Procede? "
Write-Host "[Y] Yes " -nonewline; Write-Host "[N] No " -foregroundcolor yellow -nonewline; $continue = Read-Host "(default is "N")"
if ($continue -match "y")
{
Set SDK Parms
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "$status" #change to "manual" to disable auto upgrade of Tools
Execute Command
get-vm -Location "$Clustername" | get-view | %{$_.ReconfigVM($vmConfigSpec)}
}
else
{
Write-Host "Script Ended Without Execution"
}
Jeff
Thanks Troy, that worked perfectly !!
jcouch, I'll give your script a go as well. That would really help when patching our clusters also. Many Thanks!!
luc: you rock!
saved my right finger from certain death clicking 1000x!
ken
This couldn't have come at a better time.
Many thanks to Luc and the OP...this is going to come in real handy next maintenance weekend.
Psyched!
did some puzzling as i never used PowerCli / PowerShell,
when i run the script of LucD for every machine that is being set get this message:
Exception calling "ReconfigVM" with "1" argument(s): "fault.RestrictedVersion.s
ummary"
At C:\script.ps1:6 char:17
+ $_.ReconfigVM <<<< ($vmConfigSpec)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
My script looks like this:
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-View -ViewType VirtualMachine | %{
$_.ReconfigVM($vmConfigSpec)
}
Any ideas?
From the error message I guess you are trying to do this on a 'free' ESXi server.
I'm afraid you only can only read on those but not write, or change anything with PowerCLI
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference