Home > Blogs > VMware vSphere Blog

Using A Guest Customization Script to Tell When vApp/VM Is Ready In vCloud Director

By William Lam, Sr. Technical Marketing Engineer

A question that has comes up from time to time for vCloud Director is how to tell when a vApp and its associated Virtual Machines is ready for use after the initial power on operation?

Screen Shot 2012-05-30 at 4.08.46 PM

If you look at the vCloud UI, the status of the Virtual Machine shows “Powered On” which is  also represented in the vCloud API using the “Status” property for a Virtual Machine. However, this status does not necessarily mean the guestOS is ready, it just means that it is powered on. The Virtual Machines could still be booting up or going through their OS customization. So how might you go about determining when the guestOS is actually ready for use?

In talking to one of my fellow colleagues over in the VMware COE (Center of Excellence), Timo Sugliani, Timo came up with a pretty neat idea by leveraging the guest customization script for a Virtual Machine. The idea was to create a file within the guestOS filesystem at the end of the “Post Customization” section which could then be checked periodically to see if the guestOS has completed its customization.

To enable guest OS customization, it is a two step process in the vCloud UI:

1) Right click on the Virtual Machine and select the “Guest OS Customization” tab and check the box “Enable guest customization”.


2) Next, att the very bottom, you can then either upload a script or paste the contents of the script. The script must be either a Windows Batch script or Linux Shell script.


Below are two sample scripts that I used to test on both a Windows and Linux VM running in vCloud Director:

Linux Script:
if [ x$1 == x”precustomization” ]; then
echo Do Precustomization tasks
elif [ x$1 == x”postcustomization” ]; then
/bin/date > /var/run/vm-is-ready

Windows Script:
@echo off
if “%1%” == “precustomization” (
echo Do precustomization tasks
) else if “%1%” == “postcustomization” (
echo %DATE% %TIME% > C:\vm-is-ready

As you can see both script is pretty simple by just printing the date into a file which is stored within the guestOS.

We can also use the vCloud API by performing a PUT operation on the Virtual machine’s guestCustomizationSection. Here is an example curl call:

$ curl -i -k -H “Accept:application/*+xml;version=1.5” -H “x-vcloud-authorization: PaHt58xx53ezIKJRYXT/VGWEricT5vh7xqyZHLEgSOY=” -X PUT https://vcd/api/vApp/vm-ab10d2ab-37da-402f-9f66-277a64c19076/guestCustomizationSection/ -H “Content-Type: application/vnd.vmware.vcloud.guestCustomizationSection+xml” -d @customization-script

Here is an example of what the customization-script file looks like:


Note: You will need to ensure the script body is in UNICODE format (e.g. < > is &lt; &gt;)

Let’s go ahead and test this these two scripts. In my lab, I have a single vApp which contains two Virtual Machines: Windows and Linux. We will go ahead and initiate the power and see when the power operation was initiated and completed.


As you can see from the above screenshot, the power on started at 4:23 PM and completed at 4:25 PM. Now if we login to our two Virtual Machines, we should see the “vm-is-ready” file in /var/run for our Linux VM and in C:\ for our Windows VM:



If you take a look at the time stamp, we can see that this file is created a few minutes after vCloud Director has noted the Virtual Machines is in a powered on state. If we had an external system which could periodically monitor the Virtual Machines, we could then send an email or notification through a custom portal on when the vApp is fully ready for use. Another option is to have the script perform a “call out” to an external system such as vCenter Orchestrator on when the Virtual Machine is ready versus polling the system.

Get notification of new blog postings and more by following lamw on Twitter:  @lamw

27 thoughts on “Using A Guest Customization Script to Tell When vApp/VM Is Ready In vCloud Director

  1. Norman

    Hi William:

    I was trying to load the windows script in Guest OS Customazation tab. But it seems like after power on, the file was not created. Do you know what the problem might be?


  2. Paul Poppleton

    I would like to point out there is an error in the sample windows batch script. %1 should be used in place of %1% .

      1. Paul Poppleton

        That is true for variables I think but for arguments passed in I seem to see them used with the single %. I am not expert though. I think %1% or %1 evaluates the same.

  3. Paul Poppleton

    One other comment on the windows batch file example. I don’t believe there is an “else if” statement only an “else”. I went witth

    if “%1” == precustomization goto :pre
    if “%1” == postcustomiztion goto :post
    goto :end

    Do some commands
    goto :end

    Do some commands
    goto :end


    1. William LamWilliam Lam Post author

      The sample batch script came out of the following KB kb.vmware.com/kb/1026614 which I also tested while writing this article. Are you saying that you’re having issues running the batch script?

  4. Pureberry Max Trial

    Just want to say your article is as astonishing. The clearness in your post
    is simply nice and i could assume you’re an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please continue the rewarding work.

  5. Sapphire Quit Smoking

    Pretty element of content. I just stumbled upon your blog and in accession capital to say that I acquire
    actually loved account your blog posts. Anyway I’ll be subscribing for your feeds or even I fulfillment you get entry to persistently rapidly.

  6. Xtreme Antler

    Hey there! I realize this is sort of off-topic but I needed to
    ask. Does managing a well-established website like yours take a massive amount work?
    I am completely new to operating a blog but I do write in my diary on a daily basis.
    I’d like to start a blog so I can easily share my own experience and feelings online. Please let me know if you have any kind of ideas or tips for brand new aspiring bloggers. Thankyou!

  7. Lawerence

    I rarely write responses, but I browsed a few of the comments here Using A Guest Customization Script to
    Tell When vApp/VM Is Ready In vCloud Director | VMware vSphere
    Blog – VMware Blogs. I actually do have a couple of questions for you if you do not mind.
    Could it be only me or does it appear like a few of the responses look as if they are written by brain dead visitors?

    😛 And, if you are posting on other online sites,
    I’d like to follow you. Would you post a list of the complete urls of your social community sites like your Facebook page, twitter feed, or linkedin profile?

  8. Uta

    No matter if some one searches for his required thing,
    thus he/she desires to be available that in detail,
    so that thing is maintained over here.

  9. Emeline Moller

    What i don’t understood is actually how you’re not really much more well-liked than you might be now. You are very intelligent. You realize thus considerably relating to this subject, produced me personally consider it from a lot of varied angles. Its like men and women aren’t fascinated unless it is one thing to do with Lady gaga! Your own stuffs outstanding. Always maintain it up!

  10. Www.Atvriders.tv

    Excellent website you have here but I was wanting to know if you
    knew of any user discussion forums that cover the same topics
    discussed here? I’d really like to be a part of group where I can get opinions from other experienced individuals that share the same interest.

    If you have any suggestions, please let me know. Kudos!

  11. webpage

    Hello! I’ve been reading your website for a while
    now and finally got the courage to go ahead and give
    you a shout out from Houston Tx! Just wanted to mention keep up the great work!

  12. affordable search engine Optimization services

    Howdy I am so thrilled I found your blog, I really found you by mistake, while I was looking
    on Digg for something else, Regardless I am here now and
    would just like to say thanks for a remarkable post and a all round exciting blog (I also love the theme/design), I don’t have
    time to go through it all at the minute but I have book-marked it and
    also added in your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the
    superb jo.

  13. admin@balkancloud.com

    I’m renting servers in vmware vcloud environment.
    I would like to do the following:
    1) shut down machine
    2) add resources like cpu & ram
    3) power on machine
    Not hot add supported in OS, restart is needed in any case.

    Is this scriptable somehow? Be aware, i don’t have full vcloud administrator access. I’m one of the customers.


Leave a Reply

Your email address will not be published. Required fields are marked *