If you are managing VMware environment you might have encountered a situation where you had to upgrade VMware Hardware version on Templates you use to deploy VMs. This could be due to environmental changes – like ESXi upgrade or any other reason. Or it could be just because you have not upgraded VMware hardware version for long and started seeing compatibility and other technical issues in your environment.
Whatever the reason may be, we periodically upgrade hardware version of templates, instead of recreating a new template. I am going to share a script today which perform this upgrade on an existing template. You need to provide Template Name, Template location, Hardware Version[e.g., VMX-10(v10),VMX-11(v11) etc.]. If you have multiple templates, you can use for-loop to upgrade all of them.
Apart from above mentioned inputs , I will as usual use vCenter name as input to the script. As I mentioned in my previous post, feel free to update this script and get those input as parameters. Here is the complete script. Let me know if you face any issue!
$vCenterName = "<VCenter FQDN>"
$templateName = "<name of template>"
$location = "<VI Container name - it could be Folder, Data center etc. in vCenter>"
$hwVersion = "<Hardware version to set>" # Example, v10,v11,v12 etc.
# connect to the vCenter
connect-viserver $vCenterName
# Get the Template and convert it to a VM and set the required Vmware Hardware version and start it
$vmUpdated = Get-Template -Name $templateName -Location $location | Set-Template -ToVM | Set-VM -Version $hwVersion -Confirm:$false | Start-VM
# wait for 60 seconds to start the VM
Start-Sleep -Seconds 60
# shutdown the VM converted from the Template to set the change
Shutdown-VMGuest -VM $vmUpdated -Confirm:$false
# again await for 120 seconds to shutdown the guest. You may change this number based on your requirement
Start-Sleep -Seconds 120
# finally set the changes and convert the VM back to template
Set-VM -VM $vmUpdated -ToTemplate -confirm:$false
# disconnect from the vcenter
disconnect-viserver $vCenterName -confirm:$false