VMware Cloud Community
jcouch
Enthusiast
Enthusiast
Jump to solution

Need script to enable "Check and upgradetools during power cycling" on all VMs

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?

Tags (1)
61 Replies
jhjkempen
Contributor
Contributor
Jump to solution

that's sad.... So now way to use powercli on esxi 4.1 free to change things?

Can i use powercli to invoke .bat file on all vmwares simultanous?

a script that would call a batch file on the vmware it self... That way i could do some update work without going to each vmware and click on the bat file...         

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid not.

And I'm afraid I can test that 2nd question, I don't have a free ESXi 4.1 available.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

what would be the code for a non-free version of esxi? I can test it on my free version:smileylaugh:

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I would try with the Invoke-VMScript cmdlet to start the BAT file.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

was already googling on that before your answer:) trying to figure out how to run this on all vmwares at the same time...    

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VM | %{
  Invoke-VMScript -VM $_ -ScriptType bat -ScriptText '<your command(s)>' -GuestUser guser -GuestPassword gpswd
}

You probably will have to add the HostUser and HostPassword as well


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

thanks for that, will give it a try. First trying to running a command on a single machine, only got screwed with having the PowerCli on my 64 bit Windows 7 machine. Invoke-VMScript needs 32bit.... Trying it for an old Vmware XP machine...    

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

any idea how to run Invoke-VMScript on a 64 bit Windows 7 machine?

googled for half an hour but no real clues...        

EDIT

stupid me, the powercli installer already made 2 icons, 64bit and 32 bit...         

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid Invoke-VMScript only runs in 32-bit.

And yes, use the 2nd icon to start PowerCLI in 32-bit mode


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

is nothing allowed on a free version of Esxi?

C:\PS>$vm = Get-VM myVM

Invoke-VMScript -VM $vm -ScriptText "dir" -HostUser root -HostPassword mypass -G
uestUser administrator -GuestPassword mypass

Invoke-VMScript : 11-5-2012 12:20:34    Invoke-VMScript        While performing
operation 'Connect to host service 'https://server1/sdk' at port 902' the foll
owing error occured: 'This operation is not supported with the current license'

Invoke-VMscript -VM $vm -ScriptText "c:\windows\explorer.exe" -HostUser root -HostPassword xxx -GuestUser guser -GuestPassword gpswd

same error...

so can't perform any action on a vmware because of the free version?
    
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I was afraid of that, only the Get- cmdlets will work with the free ESXi version.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jhjkempen
Contributor
Contributor
Jump to solution

that sucks. we gonna have to stuck with the schedule.bat that is running each night on the vmware.

Reply
0 Kudos
faf1967
Contributor
Contributor
Jump to solution

What if the server does not have the tools installed, will this check mark install the tools? I do not think it will but I wanted to throw it out there just in case.

What are some ways that you install the tools from a remote PC where you can not reboot a server?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could use the Mount-Tools cmdlet and then use the method described in KB1018377 through Invoke-VMScript.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RichEB
Enthusiast
Enthusiast
Jump to solution

Is there a way to run this against a list of VM's? I have some VM's that I do not want to update the tools on and was wondering if it would be simple to run this script against a list of ones that I want to change to "UpgradeAtPowerCycle"

Thanks

Rich

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The selection of the targetted VMs is done with the Get-VM cmdlet.

Without any parameters it will return all VMs known in your vCenter or ESXi host.

You can use the Name parameter with a specific or a partial name.

Get-VM -Name VM*

This will return all VMs whose name starts with VM.

Or you can use a Where-clause to filter out the VMs you want.

Get-VM | Where {$_.NumCpu -eq 2}....

Or you can even store the names in a file, read the content and use those on the Name parameter

Get-VM -Name (Get-Content vmnames.txt)

And there are many other possibilities.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RichEB
Enthusiast
Enthusiast
Jump to solution

I have the list, I need a way to use that list to change the setting on only those vm's.  I was thinking maybe something like below:

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

$vms = get-content "c:\list\vms.txt"

For-each $vm in $vms {

Get-View -ViewType VirtualMachine -filter @{"Name" = "$vm"} | %{$_.ReconfigVM($vmConfigSpec)}

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should work as well.

With Get-View you retrieve the actual vSphere object.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
dhenry123
Contributor
Contributor
Jump to solution

Check this link for an option to change this setting - easily configured through vUM.

http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vsphere.update_manager.doc%2FGUID-6F...

To enable upgrading of VMware Tools on power cycle, use one of the following options.

Option

Action

VMware Tools upgrade settings

a

On the Home page of the vSphere Client , select VMs and Templates and click the Update Manager tab.

b

Select a virtual machine or a container object from the inventory.

c

Click VMware Tools upgrade settings.

d

In the Edit VMware Tools upgrade settings window, select the check boxes of the virtual machines for which you want to enable VMware Tools upgrade on power cycle.

e

Click Apply.

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Do this script works for the vSphere 5.1 Update 1 ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos