Partilhar via


How to get Job progress from SCVMM

Hey guys,

   In this post I will discuss a question that has come my way a few times. This post will discuss how to get the percentage of a job task from SCVMM that you may use in your custom applications to allow your end users to watch the progress of a task performed on a VM being managed by SCVMM. This post will assume you are familiar with programming against SCVMM via both powershell and C#. If you are not familiar with these concepts, please review my previous blog posts to get started.

   I will not delve into the understanding of the SCVMM tables stored in SQL. I wll highlight which tables contain the information we need to perform our desired task. Please note, that any modifcation to the SCVMM database (default name VirtualManagerDB) is unsupported. Any modifications to this database may break your existing SCVMM setup, and Microsoft may not assist you with recovery of this data, as modifications to this database are unsupported.

   The first table we will need to look is the "tbl_WLC_VObject table". This tables contains base information for SCVMM objects (VMs, Templates, etc). You can differentiate the different objects by their object type found in this table. For example, objecttype "1" is a virtual machine, object type "3' is a template. The field we're going after is the "FailedJobID" field. This field will either contain a NULL value or a GUID. We will need this GUID to look up the progress status. There are tons of different ways you may wish to filter for this GUID, but to keep it simple, I'll just go with:

SELECT [FailedJobID]

  FROM [VirtualManagerDB].[dbo].[tbl_WLC_VObject]

  WHERE ObjectType = 1 AND Name = 'MyGreatVM'

  
So far so good. We now have a GUID to represent the JobID for the job in question. From this point on I will refer to this GUID as JobID.

   The last thing we will need to do is query the table called "tbl_TR_SubtaskTrail" to get our completion status. Remember that this will continuously change as the status progresses so you will want to keep comming back and checking this table until your task is done. Here's what we will use:

    I've added a bit more logic in my query to insure that I am targetting a task description of "NewVM". In this example, we will assume that we are going to get progress status for a new VM that is building. The addition of the Description ='NewVM' feild insures that I only get progress for this particular task (the New VM build task).

SELECT PercentComplete

FROM tbl_TR_SubtaskTrail

WHERE tbl_TR_SubtaskTrail.TaskID = @JobID

AND Description = 'NewVM'

  
That's it, you can now use this display data wherever you like to keep you clients informed of the percentage complete of a task in SCVMM. I have also showed how to give a little extra insurance that you are tracking the task that you are looking for by using an extra WHERE clause against the Description field.

   In reality you will probably not want to call this SQL statement from code in a loop unitl you hit 100 percent. You will want to instead create a stored procedure instead in SQL and call that stored procedure with a parameter value of JobID. This is the least expensive way to get the data, and allows SQL to do it's job (which is all the work).

   As always enjoy!