Looking at Tasks under Virtual Server

Looking at Tasks under Virtual Server

  • Comments 5

Whenever Virtual Server has a task to complete (like merging a hard disk) that may take a while - it creates a task object.  You have probably seen these used in some of my scripts when I want to wait for a task to complete before moving onto the next step.  These task objects are really quite useful - and expose some interesting information.

The script below will retrieve all active task object from a Virtual Server instance - and then display the Task ID, description and percentage completion:

Set vs = CreateObject("VirtualServer.Application")

Set tasks = vs.Tasks
If tasks.Count = 0 Then
    Wscript.Echo "There are no tasks"
Else
    Wscript.Echo "Active tasks: "
    For Each task in tasks
        Wscript.Echo "    Task: " & task.ID & " : " & task.Description & " : " & task.PercentCompleted
    Next
End If

Cheers,
Ben

Leave a Comment
  • Please add 1 and 4 and type the answer here:
  • Post
  • So, is the main purpose of a task object to give you the ability to either programmatically wait for the task to complete (i.e. serial) or to move on to some other activity (i.e. parallel)?


    Something like "start notepad" and "start /wait notepad" ?
  • Phylyp - Yup.

    See my past blog entries on how it works. CSCRIPT is the required host for the percentage display to work. I can also wire this up into a popup dialog that dynamically shows percentage complete of the Task.

    Reusable function to wait for any Async Task:
    http://blogs.msdn.com/david.wang/archive/2005/07/21/HOWTO_Wait_for_Asynchronous_VirtualServer_Tasks.aspx

    How to wait for Virtual Machine to finish saving/restoring/starting/turning-off:
    http://blogs.msdn.com/david.wang/archive/2005/10/18/HOWTO_Remotely_start_and_stop_a_Virtual_Machine_on_Virtual_Server_2005.aspx

    Notice you have to wait for the VM to finish saving/turning-off before attempting to copy the VHD backup file, and then turn the VM back on...

    //David
  • David: Thank you for your answer, as well as the references to your articles.
  • Thanks for all the info on the "API of Virtual Server". Makes me wonder, though ... I see an opportunity for someone to make an overall GUI to manage VS that would include stuff that there are API's for that the web site does not expose today. VMWare has VirtualCentre that is a competitive advantage. Any MS plans for this? Or leaving it for 3rd party?
  • James - No, the website pretty much exposes the entire API and has a machine-centric view. There are no special API calls to make "VirtualCenter" that is not exposed.

    What you are talking about is a Product that utilizes the same APIs in a different manner to produce a different concept (merge  multiple machines into a logical view) that is suitable for other usage models.

    This is why Microsoft provides an API - so that anyone can do what they need, stand on the shoulders of giants, and exploit any business opportunities.

    Microsoft is a platform company that fosters and depends on a thriving 3rd party development community to make its platform attractive and successful.

    Products like Virtual Center can easily be built on the Virtual Server Administration API. Someone just has to do it. And it shouldn't be Microsoft by default. For example, I've got designs to do this from just a commandline application, but I should not be the only choice in town.

    Think about it another way - for VMWare, there is only one source for advancements in the technology/feature set - VMWare itself. For Virtual Server, with a public API, there is Microsoft and any 3rd party developer in the same space. Which model do you think long-term innovation and scalability will reside?

    But when the customer assumes that Microsoft should do everything -- that's when it all can fail.

    //David
Page 1 of 1 (5 items)