Creating and Deploying Templates

Introduction to Creating and Deploying Templates

Version: vSphere 5.5

One of the benefits of VMs is how easy they can be cloned – gone are the days of having tediously install OSes or wrestle with complicated scripted deployment tools. vSphere offers a number of different method of duplicating VMs. Firstly, a VM whilst powered on can be cloned. This can be useful if you want a perfect copy of existing production VM for testing purposes or for use in an development environment. However, care must be taken not to create hostname and IP conflicts with the original source VM. Typically, people patch the cloned VM to different portgroup or temporarily disconnect the network card.

An existing VM can be cloned into the template format, or converted into a template. The difference is really if you want to keep the existing VM for another purpose, or if you want avoid an unnecessary copy process. A template is very similar to a VM, the only difference really is instead of having a .VMX file, it has .VMTX file registered with vCenter. In this state the VM cannot be powered on and modified, unless it is converted back into a VM. The vSphere Web Client also supports the copying of template into another template.

All the different clone/convert options are available from the New Virtual Machine Wizard:

Screen Shot 2014-04-30 at 14.21.23.png

Also on the right-click of a VM you will see Clone to Virtual Machine and Clone To Template

Screen Shot 2014-04-30 at 14.22.09.png

You will find the Covert to Template option under All vCenter Actions on the right-click of a VM

Screen Shot 2014-04-30 at 14.25.10.png

Clone an existing VM

1. Open the New Virtual Machine wizard, and select Clone an existing virtual machine

Screen Shot 2014-04-30 at 14.43.45.png

2. Next explorer the inventory to select VM you wish to clone

Screen Shot 2014-04-30 at 14.45.12.png

The option to Customize the Operating System will trigger the use of Sysprep in Windows and customization scripts in Linux to allow for the renaming and re-ip of the VM. In the case of Windows it can also facilitate the process of joining the Microsoft Active Directory domain. The option to Power on Virtual Machine after creation will power on the VM after the clone process has completed – this potential cause problems if customization has happened or if the VM is place on the same network segment as the source. The option to Customize this virtual machine’s hardware (experimental) has been marked as experimental for sometime by VMware, it allows to modify the assignment of memory, CPU and other resources to the VM prior to the clone process powering on the VM.

3. Next, set a name for the cloned VM, and a location in the vCenter Inventory

Screen Shot 2014-04-30 at 15.52.08.png

4. Select a Host, Cluster or Resource Pool to that will provide resources to the clone

Screen Shot 2014-04-30 at 15.55.56.png

5. Next select a datastore to hold the cloned. The option for the disks to be use the Same format as source – will ensure if the source is using thickly provisioned disks, the cloned VM will as well – and if the source is thinly provisioned the virtual disks of the clone VM will be same as well. The pull-down list does allow the administrator over-ride this – and change the target cloned disk format if necessary.

Screen Shot 2014-04-30 at 15.57.32.png

Note: Once the clone has completed you can edit it settings, patch it to different network and power it on.

Convert to Template

The Convert to Template option is a very quick and easy method to take an existing VM and turn it into a template. The main advantage is the conversion process takes seconds, as no copy process takes place. The VM is merely unregistered, and re-registered with vCenter as template. One the primary advantages is that it is as quick to take a template, and convert it back to being a VM again. This assists with keeping the VM up to date. For instance, once a month a template could be converted back into a being a VM and powered on – then various software updates could be carried out such as Windows Update, YUM Update or other ancillary software updates such as Anti-virus,.NET, Java and Flash updates. Once these updates have been completed the VM can be powered off, and converted back to template – ensuring that any newly deployed VM is using the most current software available.

1. Locate the VM in the VM and Templates View, and gracefully shutdown the VM that will be converted to a template

2. Right-click the VM, and under vCenter Actions, select Convert to Template

Screen Shot 2014-04-30 at 14.25.10.png

Note: If you are in the Host & Cluster view you should see that VM disappears. This is because templates are not shown in this view. Switch to the Virtual Machine and Templates view if this is the case. You should notice that icon has change for the VM “boxes in boxes” icon to one that resembles a folder of paper. If you have created VM Folders to hold your templates you use drag and drop to relocate them.

Screen Shot 2014-04-30 at 16.31.31.png

Deploy Template
Deploy a VM from a template

It’s possible to deploy a VM from template using the New Virtual Machine Wizard, and its also possible to right-click the template and also Deploy VM from this template, Convert to Virtual Machine and Clone To Template

Screen Shot 2014-04-30 at 17.08.25.png

1. Open the New Virtual Machine wizard, and select Deploy from template

Screen Shot 2014-04-30 at 17.10.56.png

2. Next explore the inventory to select the template you wish to wish to use as the source. In this case we will use all of the options available to show the full functionality.

Screen Shot 2014-04-30 at 17.12.41.png

3. Next, set a name for the new VM, and a location in the vCenter Inventory

Screen Shot 2014-04-30 at 17.16.57.png

4. Select a Host, Cluster or Resource Pool to that will provide resources to the VM

Screen Shot 2014-04-30 at 17.17.28.png

5. Next select a datastore to hold the VM. The option for the disks to be use the Same format as source – will ensure if the source is using thickly provisioned disks, the cloned VM will as well – and if the source is thinly provisioned the virtual disks of the clone VM will be same as well. The pull-down list does allow the administrator over-ride this – and change the target cloned disk format if necessary.

Screen Shot 2014-04-30 at 17.17.49.png

Guest Customization from a Template (Windows)

IMPORTANT:

Whilst vSphere supports one of the widest range of guest operating systems available – that does not mean all OSes are supported for Guest Customization. This is particularly significant when it comes to Linux distributions where the sheer vast array of Linux distributions, and the rapidity of their release restricts the Guest Customization options. However, there cases where a Windows OS is supported by vSphere, but not for Guest Customization for instance Windows 2000 is no longer supported for guest customization. In terms of Linux, CentOS is not supported for Guest Customization at all (although it is a support guest operating system), and as such if a template is made from it and deployed as a VM the administrator will receive this warning:

Screen Shot 2014-05-13 at 09.52.22.png

This is a recent list of Windows Systems and their status in terms of Guest Customization Support:

  • WindowsServer2012R2 – Yes
  • WindowsServer2012 -Yes
  • WindowsServer2008R2 – Yes
  • WindowsServer2008 Yes
  • WindowsServer2003R2 – Yes
  • WindowsServer2003 – Yes
  • WindowsServer2000 – No
  • Windows8.1 – Yes
  • Windows8 – Yes
  • Windows7 – Yes
  • WindowsVista – Yes
  • WindowsXP – Yes

WARNING: In order for some Windows OS to join the domain during using Sysprep a DHCP IP address must assigned during the customization process. This is despite the fact you may assigned a static IP address with the Guest Customization Specification – many Sysprep clients default to DHCP on the first boot. Without a valid IP address the VM will not join the domain.

6. At this stage the administrator will see the Guest Customization window. In a clean installation this will be blank. The screen grab below shows an environment where some guest customizations specs have all already be saved. Guest Customizations hold the typical question need to automate the generalization of the guest operating system. The question asked can be saved to guest customization spec settings which saves lots of time – by not having to set variable such as Computer Name, Windows License, Administrator Password, Time Zone, Run Once, Networking and Domain membership. The guest customization wizard differs from Windows to Linux so its look and feel alters depends on the OSes contained in the template.

The page icon with a green plus, can be used to add a new customization spec

Screen Shot 2014-04-30 at 17.28.15.png

Note: When this icon is clicked the Deploy from template wizard is minimised to Work in progress pane, and the New VM Guest Customization Spec window is loaded

Screen Shot 2014-04-30 at 17.29.28.png

7. The first part of the Guest Customization Wizard requires a friendly name to inputed, together with an optional description.

Screen Shot 2014-04-30 at 17.36.29.png

Note: Some Windows Administrators have spent time developing sysprep.inf files, and these can be re-use and uploaded into the Guest Customization Wizard if you prefer

8. Set Registration Information allows the administrator to configure the user name and organization

Screen Shot 2014-04-30 at 17.40.17.png

9. Next we can set the Computer Name. It is possible to input manually, and have that name appended with unique characters. Alternatively, we can make sysprep make set the computer name to be the same as name specified in the Deploy from template wizard – alternatively we can pause the cloning process to ask the user to set the computer name. Finally, custom applications can be registered with vCenter to set the name, and hold this as record in a database.

Screen Shot 2014-04-30 at 17.46.05.png

10. For operating systems that require it you can configure Enter Windows License key. This can be useful if their is KMS service available and the organisation is using Windows Datacenter licensing which allows unlimited copies to run. Not all Windows editions require a license key to function – for instance Windows 2008 R2 does not require a license to be installed

Screen Shot 2014-04-30 at 17.48.34.png

11. The next part of the wizard allows you to set the Local Administrator Password. The Automatically logon as Administrator option automates the Ctrl+Alt+Del login process in Windows to allow for further post-scripting and tooling of Windows. This can be used in conjunction with the Run Once options to call those scripts.

Screen Shot 2014-04-30 at 17.55.30.png

12. Next configure the Time Zone for the VM

Screen Shot 2014-04-30 at 17.56.14.png

13. The Run Once option allows the administrator to call additional post configuration scripts

Screen Shot 2014-04-30 at 17.57.23.png

14. The Configure Network, allows the administrator set the VM to use either a DHCP address or configured with a Manual IP Address. If a manual IP address is selected again the administrator can opt to set a Static IP Address or stall the customization process to allow an operate to set it manually.

Screen Shot 2014-04-30 at 19.32.20.png

Once selected, the “pencil icon” can be used to the edit the IP configuration – with the DNS options allowing the administrator to set the DNS Suffix, and WIN option to configure the Primary/Secondary WINS server(s) if present.

Screen Shot 2014-04-30 at 19.35.22.png

15. Next Set Workgroup or Domain, allows the administrator to join the VM to a Microsoft Active Directory Domain. Starting from Windows 7/2008 many people in the community report that the most reliable method of doing this is to use domain.com notation, rather than the more classic DOMAIN\Username format.

Screen Shot 2014-04-30 at 19.35.54.png

16. Set Operating System Options – allows the administrator to force sysprep to regenerate the Security Identify or SID that is just in Windows to unique identify a node on the network.

Screen Shot 2014-04-30 at 19.36.08.png

17. Once the Guest Customization Wizard has completed the wizard will be dismissed and the Deploy VM from a Template wizard will appear allowing the administrator to select the Guest Customization Spec from the list.

Screen Shot 2014-04-30 at 19.36.38.png

Completing Deploy From Template

18. Once the Guest Customization has been selected, the Deploy From Template will return. If selected the administrator will be able adjust the VM settings – such as adding more vCPUs, Memory, and patching the VM to the correct network.

Screen Shot 2014-04-30 at 19.37.32.png

Once the VM is powered on Windows will trigger the Guest Customization process. In tests the complete sysprep process took around 6mins to complete in Windows 2012 R2. This involves three reboots – Windows boots for the first time, and then reboots – and then it reboots a second time. You can tell whether Guest Customization/Sysprep has completed as Windows 2012 R2 will not initially show the right time zone:

Screen Shot 2014-04-30 at 20.57.24.png

Note: Before Guest Customization Time Zone is Pacific Time

At the second boot you should see Windows splash “VMware image customization is in progress…”

Screen Shot 2014-04-30 at 21.02.29.png

The Administrator should also see Windows splash “Getting Devices Ready” and “Getting Ready”. At this stage the VM is joined to the domain, and Windows is rebooted again. It’s at this stage that the VM is ready for use.

Screen Shot 2014-04-30 at 20.57.48.png

Note: After Guest Customization Time Zone is GMT

Guest Customization from a Template (Linux)

IMPORTANT:

Whilst vSphere supports one of the widest range of guest operating systems available – that does not mean all OSes are supported for Guest Customization. This is particularly significant when it comes to Linux distributions where the sheer vast array of Linux distributions, and the rapidity of their release restricts the Guest Customization options. However, there cases where a Windows OS is supported by vSphere, but not for Guest Customization for instance Windows 2000 is no longer supported for guest customization. In terms of Linux, CentOS is not supported for Guest Customization at all (although it is a support guest operating system), and as such if a template is made from it and deployed as a VM the administrator will receive this warning:

Screen Shot 2014-05-13 at 09.52.22.png

This is a recent list of Windows Systems and their status in terms of Guest Customization Support:

  • RedHatEnterpriseLinux 6.x – Yes
  • RedHatEnterpriseLinux 5.x – Yes
  • RedHatEnterpriseLinux 4.x – Yes
  • RedHatEnterpriseLinux 3.x – No
  • RedHatEnterpriseLinux 2.1 – No
  • SLES11 SP3 – Yes
  • SLES11 SP2 – Yes
  • SLES11 SP1 – Yes
  • SLES11 SP0 – No
  • SLES10 SP4 – Yes
  • SLES10 SP3,SP2, SP1, SP0 – No
  • SLES9 – No
  • SLES8 – No
  • Ubuntu13.1 – Yes
  • Ubuntu13.04 – Yes
  • Ubuntu12.1 – Yes
  • Ubuntu12.04 LTS – Yes
  • Ubuntu11.10 – Yes
  • Ubuntu11.04 – Yes
  • Ubuntu10.10 LTS – Yes
  • Ubuntu10.04 – Yes

6. At this stage the administrator will see the Guest Customization window. In a clean installation this will be blank. The screen grab below shows an environment where some guest customizations specs have all already be saved. Guest Customizations hold the typical question need to automate the generalization of the guest operating system. The question asked can be saved to guest customization spec settings which saves lots of time – by not having to set variable such as Computer Name, TimeZone, Networking and DNS/Domain settings. The guest customization wizard differs from Windows to Linux so its look and feel alters depends on the OSes contained in the template.

The page icon with a green plus, can be used to add a new customization spec:

Screen Shot 2014-05-14 at 17.51.25.png

Screen Shot 2014-05-14 at 16.39.36.png

Note: When this icon is clicked the Deploy from template wizard is minimised to Work in progress pane, and the New VM Guest Customization Spec window is loaded

7. Next we can set the Computer Name. It is possible to input manually, and have that name appended with unique characters. Alternatively, we can make the system make set the computer name to be the same as name specified in the Deploy from template wizard – alternatively we can pause the cloning process to ask the user to set the computer name. Finally, custom applications can be registered with vCenter to set the name, and hold this as record in a database.

Screen Shot 2014-05-14 at 16.42.02.png

Note: It’s recommend to use lower-case for the VM name to ensure the hostname in Linux is set in lower-case as well.

8. Next the TimeZone that is appropriate for the VM.

Screen Shot 2014-05-14 at 16.42.43.png

9. The Configure Network, allows the administrator set the VM to use either a DHCP address or configured with a Manual IP Address. If a manual IP address is selected again the administrator can opt to set a Static IP Address or stall the customization process to allow an operate to set it manually.

Screen Shot 2014-05-14 at 16.43.39.png

Once selected, the “pencil icon” can be used to the edit the IP configuration – with the ability to set the IP/Subnet Mask/Default Gateway and Alternative Gateway

Screen Shot 2014-05-14 at 16.44.21.png

10. Finally, the administrator can configure the Primary, Secondary, Tertiary DNS IP Addresses together for the default DNS Search Path.

Screen Shot 2014-05-14 at 16.44.56.png

11. Once the Guest Customization Wizard has completed the wizard will be dismissed and the Deploy VM from a Template wizard will appear allowing the administrator to select the Guest Customization Spec from the list.

Screen Shot 2014-05-14 at 16.45.42.png

Convert to Virtual Machine

Once a VM has been converted to a template, it can be converted back to being a VM again. This will allow the administrator to power on the VM, and carry out any updates to the source VM. These updates could included updating VMware Tools, Upgrading Virtual Hardware or updating the software inside the VM such as applying a Service Pack or updating other components such as .NET or Anti-virus software.

1. Locate the VM in the Virtual Machines & Templates view, right-click the template, and select Convert to Template

Screen Shot 2014-05-12 at 11.36.03.png

2. In the wizard, select a Host or Cluster that will support the VM – and then click Next and Finish

Screen Shot 2014-05-12 at 11.37.33.png

In the background the VMs .vmtx file is unregistered and renamed to be a .VMX file. The process of converting a VM to/from a template does not involve a lengthy copy method and is the quickest way to keep template contents up to date. You should see the icon that represents the object toggle between the “Boxes-in-boxes” logo for the VM, to the “notebook” view of the template:

Screen Shot 2014-05-12 at 11.41.32.png

Screen Shot 2014-05-12 at 11.41.28.png

Uploading Sysprep to vCenter

Since Windows Vista, the SysPrep package has been “built-in” to Windows, and is generally to be located within C:\Windows\System32\sysprep. Prior to this change all previous Microsoft Windows OSes shipped with a version of Sysprep that was either on the original CD-ROM .iso or downloadable from Microsoft website. Additionally, Microsoft released more than one version of Sysprep for Windows based on their releases of Services Packs. For these older legacy Windows editions the SysAdmin will need to located the SysPrep packages into a folder structure on the Windows vCenter, or upload them as bundle on the vCenter Server Appliance (VCSA). This is because unlike other freely downloadable software from Microsoft, Sysprep is not free distributable by the third-parties such as VMware.

If this task is not completed the option to use Guest Customization options during the creation of a VM from a template where the source is an older legacy Windows operating system will not be available:

Screen Shot 2014-05-12 at 11.59.21.png

The VMware KB1005593 outlines this issue as well offering links to all the different version of Sysprep that Microsoft has released. These can be downloaded in their .EXE format, and extracted with the /X switch the Sysprep.exe file is found in a deploy.cab usually contained in a folder. Once sysprep has been extracted they can be copied to appropriate folder at C:\ProgramData\VMware\VMware VirtualCenter\Sysprep on the Windows vCenter.

Screen Shot 2014-05-12 at 11.56.26.png

In the case of the VCSA the appliance pages which are available on port 5480 offers a button to upload the SysPrep packages there:

1. Login as root to the VCSA at https://<your-vcenter-fqdn>:5480

2. In the vCenter Server tab, and Summary column locate the pane called Utilities which contains the button to Upload Sysprep files

Screen Shot 2014-05-12 at 13.22.57.png

The UI allows the SysAdmin to select each directory (XP, srv2003 and so on) and using the Browse button locate the correct version of SysPrep for each respective Windows edition in use. When carrying out this upload process every file found in the Deploy.cab file along side the core Sysprep.exe must be upload as well.

Screen Shot 2014-05-12 at 13.49.10.png

Sadly, the upload engine does not support multiple select to upload all the files. You may find it more efficient to use the SCP protocol with a utility like WinSCP to copy across the Sysprep Files. The directory where these files are held on the VCSA is /etc/vmware-vpx/sysprep, and each OS type has a corresponding directory that is similar to the Windows version of vCenter.

Screen Shot 2014-05-12 at 13.53.42.png

Managing Guest Customizations

Guest Customization settings are located under Rules and Profiles, and there is shortcut to Customization Specification Manager on the vCenter homepage.

Screen Shot 2014-05-12 at 14.11.06.png

Both of these options will take the SysAdmin to the same location where existing guest customizations can be located.

Screen Shot 2014-05-12 at 14.41.34.png

From here the SySadmin can:

  • Create a new specification
  • Import a specification from a Sysprep.inf file
  • Edit an existing specification
  • Delete an existing specification
  • Copy/Duplicate an existing specification
  • Export a specification to a file into a .XML format

Simple Guest Customization Specification -Scripting Example

Due to the innumerable reboots that operating systems like Windows 2012 R2 undergo, it can be difficult to know exactly when the deployment process has completed. One illustration of post-scripting with Guest Customization is using the Microsoft “msg” command to send messages to management terminal indicating that the process has completed. This involves creating a small batch or .cmd file within the template to send the message, and an call out in the Guest Customization Spec for the associated VM. The Msg command assumes the session being receiving is in RDP, and in Windows 7/8 you may well need to adjust the registry to allow the communication to flow. By using regedit to navigate to: HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server, and then change the following value to AllowRemoteRPC by 1.

In this case the script called SendMessageToMike.cmd created. The first line creates a simple “message.txt” file which includes Microsoft environment variables to ensure the hostname and domain name is correctly reported. The second line sends a message to the management PC called “mikelaverick-pc” using the contents of the message.txt. Finally, the temporary “message.txt” file is deleted the locally logged on administrator is logged out.

echo The VM called %computername% has completed the Sysprep process. It is now ready for use > c:\message.txt
msg administrator /server:mikelaverick-pc < c:\message.txt
del c:\message.txt
logoff

On the properties of the Guest Customization, Administrator AutoLogon is enabled, and the RunOnce options are configured to run the script. It’s important to note that this autologon is to the local administrator, not to the domain – and it takes place after the VM joined the domain. Any scripting that requires domain rights will need to take this into account.

Screen Shot 2014-05-12 at 18.14.34.png

Screen Shot 2014-05-12 at 18.14.46.png

Once the VM has joined the domain, the auto-login process should occur, and the script will execute producing this message on the destination management system.

Screen Shot 2014-05-13 at 10.58.32.png

Typical Template Gotchas

In many case administrators forget that when they take a VM, and convert/clone it to template – that this is an exact duplicate of the VM, and therefore any new VMs made from it will inherit those settings. It’s not uncommon that devices such as the CD-ROM is still connected and in use. Additionally, the template inherits the network settings for its portgroup association. Unless the operator using the template use the option to adjust the virtual hardware, the VM could be patched into the wrong network or no network at all – this complicates matters further when secondary process such as SysPrep fail to join the VM to the domain.

Creating and Deploying Templates (PowerCLI)

Screen Shot 2013-10-21 at 14.01.16.png

Converting a VM to a Template:

Converting an existing VM to a template is a single one-liner PowerCLI command using the cmdlet Set-VM. The cmdlet uses the existing parameters (cluster, VM Folder, Datastore) as its it location.

Set-VM Win2012-R2 -ToTemplate -Confirm:$false

Converting a Template to a VM:

Converting a template to a VM is a single one-liner PowerCLI command using the cmdlet Set-Template. Again the cmdlet uses the existing parameters (cluster, VM Folder, Datastore) as its it location.

Set-Template -Template Win2012-R2 -ToVM

Converting Many Templates To VMs:

Here Get-Template is used to find any template starting with Win its name, and then uses a Foreach loop to convert each one into a VM.

Foreach ($vmtemplate in (Get-Template Win*))
{
 Set-Template -Template $vmtemplate -ToVM
}

Converting Many VMs to Templates:

Here Get-VM is used to find any VM beginning with Win, and use Set-VM to convert the VMs into Templates

Foreach ($vmtemplate in (Get-VM Win*))
{
 Set-VM $vmtemplate -ToTemplate -Confirm:$false
}

Creating a New VM from a Template:

New VMs from existing templates can be created with a very simple script that reference the various variables required to create the VM including such requirements as the VM name, Template, Datastore, ResourcePool (which can be the host, cluster or resource pool name), VM Folder location and what Guest Customization to use.

New-VM -Name corphqdb03 -Template win2012-R2 -Datastore platinum -ResourcePool GoldCluster01 -Location CorpHQ -OSCustomizationSpec "Windows 2012 R2 - CorpHQ"
Start-VM corphqdb03

Creating Multiple VMs from a Template:

In this example a small linux distribution called Slitaz was used to reduce the time to complete the clone options. The script creates 10 VM number corphqdev01, corphqdev02 and so on. The -RunAsync speeds up the operation by not waiting for the clone to complete before the script loops around to carry out the next clone.

1..10 | Foreach {$Num = "{0:00}" -f $_
  New-VM -Name corphqdev"$Num" -Template SliTaz -Datastore platinum -ResourcePool GoldCluster01 -Location Corphq -RunAsync
}

Once the VMs have been created they can be powered on using simple wildcard based one-liner with:

start-vm corphqdev*

Upgrade Virtual Hardware and VMware Tools of a Single Template:

IMPORTANT: Remember non-interactive updates automatic updates of VMware Tools is not fully supported for non-Windows OSs. Manual intervention might be required. In our experience attempting to automate the update VMware Tools with PowerCLI is harder than it first seems. You might prefer to use VMware Update Manager which handles the process with less heartache.

It’s tricky to automate the upgrade of virtual hardware and VMware Tools without the PowerCLI script becoming convoluted. For instance the script below could made infinitely more sophisticated by first check if the VM’s virtual hardware and VMware Tools is already up to date before starting the process. Additionally, some guest operating systems will take longer to shutdown than others, especially if Windows Update manager is enabled, and updates have been set to download and install on shutdown. The Set-VM cmdlet contains the option upgrade the Virtual Hardware Level (currently v10 in vSphere5.5), and Update-Tools can silently upgrade VMware Tools. Its supports a -noreboot flag which stops the guest OS initiating a reboot – this essentially send .MSI commands to the install of /s /v”/qn REBOOT=ReallySuppress?. This doesn’t guarantee that the Windows VM will not be rebooted at the end. The vSphere5.5 PowerCLI Reference guide toUpdate-Tools makes this statement:

…virtual machine might still reboot after updating VMware Tools, depending on the currently installed VMware Tools version, the VMware Tools version to which you want to upgrade, and the vCenter Center/ESX versions.

There are couple of anomalies when carrying out this process. Firstly, it’s best upgrade VMware Tools first, before upgrading the Virtual Hardware. VMware KB1010675 outlines circumstances where network settings can be lost/modified. This is because new hardware can be recognised during the upgrade of the hardware, which might not be recognise properly until VMware Tools is up to date. Secondly, You may also need to deal with VM Question such as the UUID value, dependent on how the VM/Template was registered on the system. Finally, the option to gracefully shutdown VMs after the install of VMware Tools may fail if the VMware Tools Service fails to start. In some cases a manual reboot of the guest OS is required to make the new VMware Tools Service start correctly.

The upgrade of VMware Tools can take sometime, and PowerCLI does not give much feedback on its progress. This can give the impression the script has hung, when it is in fact still busy working. This can be difficult if the script itself has hung or the VM is requiring interaction at the console to proceed.

A good example of a much more sophisticated script for upgrading VMware Tools can be found at http://ict-freak.nl/2009/07/15/powercli-upgrading-vhardware-to-vsphere-part-2-vms/

$vmname = "Win2003" 
Set-Template -Template $vmname -ToVM
Start-VM $vmname | Wait-Tools
Update-Tools -NoReboot $vmname
Shutdown-VMGuest $vmname -Confirm:$false
Sleep 300
Set-VM -VM $vmname -Version v10 -Confirm:$false
Set-VM $vmname -ToTemplate -Confirm:$false

Upgrade Virtual Hardware and VMware Tools of a Multiple Templates:

Foreach ($vmtemplate in (Get-Template Win*)) { Set-Template -Template $vmtemplate -ToVM } Foreach ($vmtemplate in (Get-VM Win*)) { Start-VM $vmtemplate | Wait-Tools Update-Tools -NoReboot $vmtemplate Shutdown-VMGuest $vmtemplate -Confirm:$false Sleep 300 Set-VM -VM $vmtemplate -Version v10 -Confirm:$false Set-VM $vmtemplate -ToTemplate -Confirm:$false }

Source: http://www.mikelaverick.com/wiki/index.php?title=Creating_and_Deploying_Templates

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s