Script to update tools in templates.
Here is a script that takes template objects and updates their VMware tools.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # Usage: <template object(s)> | .\Upgrade-ToolsTemplate.ps1 # Example: Get-Template template1 | .\Upgrade-ToolsTemplate.ps1 # Get-Datacenter corporate | Get-Template | .\Upgrade-ToolsTemplate.ps1 # Note: When getting template make sure to get the correct datacenter in case # there are duplicate names. BEGIN { $sleeptime = 60 } PROCESS { "Converting {0} to VM" -f $_.Name $vm = $_ | Set-Template -ToVM "Powering on the VM: {0}" -f $vm.Name $vm | Start-VM | Out-Null #TODO: Find a better way of doing this than just sleeping. Perhaps poll # on tools status. "Sleeping for $sleeptime seconds" Start-Sleep -Seconds $sleeptime $vmview = Get-View $vm.ID "Existing Tools Version {0}" -f $vmview.config.tools.toolsVersion "Upgrading Tools" $vm | Update-Tools "Sleeping for $sleeptime seconds" Start-Sleep -Seconds $sleeptime $vmview = Get-View $vm.ID "New Tools Version {0}" -f $vmview.config.tools.toolsVersion "Powering off the VM: {0}" -f $vm.Name $vm | Stop-VM -confirm:$false | Out-Null "Converting to template" $vmview.MarkAsTemplate() } |
Categories: Scripting, System Administration, VMware