vCloud Automation Center – vCAC 5.1 – Executing Scripts with the Windows Guest Agent

Caution: Articles written for technical not grammatical accuracy, If poor grammar offends you proceed with caution ;-)

There are a few components to executing scripts in a Windows Guest OS which I’m going to cover in this post. Those items are:

  • Windows Guest Agent
  • Custom Properties

Windows Guest Agent – UPDATED!

Note: Due to a bug in this version of the agent installer that prevents it from being properly removed from the guest machine I recommend you use the process I define in Automated Install of Windows Guest agent to install the agent. You can follow the article and automate the installation or perform the steps manually in your template to achieve the same result as outlined in this article, without the side affect of the agent staying resident on your deployed machines.

The Windows Guest Agent has a number of feature benefits that you receive if you utilize it. The Windows guest agent is a small agent that acts very similarly to the vCAC proxy agents. When it is installed you give it the name or IP address of the vCAC server. This allows it to check in with the server when it loads on a newly provisioned machine and determine if there is anything it needs to do. If the vCAC server has work for it to do it send the instructions and the agent executes the instructions on the local guest operating system. Once the guest agent is finished performing the work assigned the last process it executes is to remove itself from the guest. The guest agent comes with a number of pre-built functions, but also allows you to execute your own scripts. Some of the features available with the Windows Guest Agent are:

Disk Operations – Partition, Format, and mount disk that is added to the machine.
Execute Scripts – Execute scripts after the machine is provisioned.
Network Operations – Configure setting for additional network interfaces added to the machine.

This article is primarily about executing scripts with the guest agent, however by installing the guest agent if you add a disk and define the proper parameters you will be able to utilize the Disk Operations that it supports. I will discuss networking in more details in a different article.

Installing the Windows Guest Agent

1. Start the “DCAC-Guest-Agent” installer by “Right” clicking and selecting “Run as administrator” from within your Windows Template Machine.
 
vcacwga-1
 

2. Click “Next“.
 
vcacwga-2
 

3. “Accept” the terms and click “Next“.
 
vcacwga-3
 

4. Give the agent a “Name” and then input the “hostname” or “IP” address of the “vCAC Server” and “Model Manager Web Service” (these may be the same). Make sure if you are not performing and https installation that you unchecked “Use HTTPS as transport protocol” and include the ports “:80” after the servers hostname or IP address.
 
vcacwga-4
 

5. Select “Guest Agent” as the agent type and click “Next“.
 
vcacwga-5
 

6. Select “Use Local System Account” instead of defining a service account and click “Next“. Note: There are pros and cons to both methods. Using the Local System Account is the safest method and has no dependencies on domain memberships etc. However windows has some strict rules as to what you can execute as the service account some some scripts may require you to use a named account.
 
vcacwga-6
 

7. Click “Install
 
vcacwga-7
 

8. Click “Finish” to complete.
 
vcacwga-8
 

9. Shut down your VM and convert it back to a template. If this is a new template make sure to do a “Data Collection” in vCAC.

Defining the Guest Agent Properties

10.Next we are going to create a “Build Profile” that we can use to hold our properties. Navigate to “Enterprise Administrator” and select “Build Profiles” then select “New Build Profile“.
 

11. Give the “Build Profile” a “Name” and then we are going to add some “Custom Properties” to the profile. We need to add the following properties and values:

  • inject.property – This is a property that I made up for this example. It is not part of vCAC.
  • VirtualMachine.Admin.UseGuestAgent – This tells vCAC to utilize the guest agent as part of the deployment process. The “value” should be “true“.
  • VirtualMachine.Customize.WaitComplete – This tells vCAC to wait until the vCenter Guest Customization is complete. If you do not use “Customization Specifications” you do not need this property. The “value” should be “true” if you use vCenter guest customization.
  • VirtualMachine.Software0.Name – Assign a name for the script you are going to execute. “Value” is a “Friendly Name” for your script.
  • VirtualMachine.Software0.ScriptPath – Path to your script including the script name. You can pass parameters to your script as well. I’m passing the value for the “inject.property” as an example of passing parameters to the script. Note: The {} brackers are required in the value. My value is “\\host\Scripts\wintest.cmd {inject.property}” This will tell the guest agent to execute the script form the unc path provided.

My wintest.cmd files simply contains:
 
echo off
echo %1 > "c:\itworked.txt"

 
vcacwga-9
 

12. Click “Ok” to save the build profile.
 

13. Go to “Enterprise Administrator“, then “Global Blueperints” and select the blueprint you want to use. Note: make sure it’s leveraging a template that has the guest agent installed. Edit the blueprint go to the “Properties” tab and select the “Build Profile” you just created. CLick “Ok” to save your blueprint.
 
vcacwga-10
 

14. Go to “Self-Service” and request a new machine. Once your machine is finished provisioning you will have a file named “itworked.txt” in the C Drive with the content of the “inject.property” custom property.

4 Replies to “vCloud Automation Center – vCAC 5.1 – Executing Scripts with the Windows Guest Agent”

  1. Hey Sid, how do we make the Guest Agent run a command as Administrator, without disabling UAC on the template entirely? We are already running the Guest Agent as a domain user that is in the the local Administrators group, although the issue is that it doesn’t have permission to run MSI installers as Administrator, so those installations fail.

    1. So disable UAC on the template and then utilize my scripts to add it back after everything else is done. It’s by far the simplest way to do it. You can also utilize run once properties in customization specs to disable it so you don’t have to in your template and then leverage the script to add it back. Sorry for the late reply.

Leave a Reply