Tuesday 8 November 2011

Auto upgrade VMware Tools on multiple Virtual Machines on next reboot

This will save huge time and effort of an administrator when he needs to update VMware tools on hundreds of VMs . Here I used PowerShell scripts to achieve the results:



Pre-Requisite :

> Windows Powershell 1.0



> VI Toolkit (login with an account, or registrar it is free)






1>Install VI ToolKit on workstation and PowerShell

2>Start the VI Toolkit

3> Connect to the Virtual Center server with command:

Command Syntax:



connect-viserver -server <VirtualCenter Server IP address> -user <VirtualCenter User> -password <VirtualCenter password>



4>Copy & Paste the following command in Toolkit Window:

 Command Syntax:

Foreach ($v in (get-vm)) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

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

$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”

$vm.ReconfigVM($vmConfigSpec)

}





press ENTER twice to start execution, Check recent task in VC progress will be shown there.



Now when your VM's Boot next time, tools will automatically installed on them.





5> Question:  Now VMTools will start getting installed every time (in future as well) VMs boot or get restarted. How to avoid this.

Ans: Once tools installed we do not wants VM's to give a check or install instructions every time when it boots. so we need to rollback the task that we did above in PowerShell script



6> to Rollback copy below script in VI toolkit windows:

Command Syntax:

Foreach ($v in (get-vm)) {

$vm = $v | Get-View }

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

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

$vmConfigSpec.Tools.ToolsUpgradePolicy = “Manual”

$vm.ReconfigVM($vmConfigSpec)

}









Voila!! you are done now..





Additional:



1>you may wants to update VMTools on specific VMs. let's say all VMs with name containing "Desktop" then you need to use below script:

 Command Syntax:

Foreach ($v in (get-vm)) {

If ( $v -like “Desktop*”) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

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

$vmConfigSpec.Tools.ToolsUpgradePolicy = “manual”

$vm.ReconfigVM($vmConfigSpec)

}

}



2> Another example, if you want set installation on Tools, on all VMs except VMs with name containing "Desktop" then you need to use below script command:

 Command Syntax:

Foreach ($v in (get-vm)) {

If ( $v -notlike “Desktop*”) {

$vm = $v | Get-View

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

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

$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”

$vm.ReconfigVM($vmConfigSpec)

}

}




No comments:

Post a Comment