Scripting a PVS Capacity on Demand Model with XenApp 6.5 Part 4

I had originally stated that this would be a 3 part series consisting of the following:

  • Analysing PVS usage
  • Adding a server to a collection
  • Removing a server from a collection

I came to the realization though that removing a server from a collection is really just the process of adding a server to a collection, except in reverse. So I don’t see the point in going over the same information again. Instead, I’m going to use the last part of this series to go over a different aspect of automation for PVS, gold image updates.

Even if you are not making any applications changes to your images, you are still going to require at least a monthly update to handle any newly released security patches. If you have a large number of images, this can suddenly turn in to a large amount of work for what is a pretty mundane task. Sounds like a perfect use case for some PVS automation to me, right?

So let’s take a look at the 3 steps that you are probably going to want to take to automate this task, these are:

  • Seal your image.
  • Promote your image to production.
  • Create a new maintenance image.

Depending on how you image is set up, you will have certain tasks that need to be completed in order to seal it for promotion. If possible, put these in to a Windows batch file and make the final line of this shut down the device as follows:

shutdown –s –t 01

We can then remotely invoke this batch file to perform the seal process for us. As you know, I love to do things with C# so here is some example code that you can use if that is your preferred route:

string resealCommand = @”cmd.exe /c C:\Reseal_Automated.cmd”;
ManagementPath run = new ManagementPath(@”\\” + vm + “\root\cimv2:Win32_process”);
ManagementClass man = new ManagementClass(run);
Object returnValue = man.InvokeMethod(“Create”, new Object[] {resealCommand});

Here I amusing the ManagementPath and ManagementClass classes to create an instance of CMD on the device that then runs the batch file to perform the seal and shutdown. Of course, this can also be done with PowerShell as follows:

Invoke-Command –ComputerName MaintenanceDeviceName –ScriptBlock {C:\Reseal_Automated.cmd}

Once the device has shutdown, we can then use the PVS PowerShell snap-in to promote the disk. We use two cmdlets’s here to get this done, firstly we use the MCli-Get cmdlet with a type of DiskInfo. From this we extract the Disk Locator ID using the string manipulation that was explained in the previous posting. Once we have that information, we can use the MCli-Run cmdlet and give it a type of PromoteDiskVersion, passing in the Disk Locator ID that we just recorded. As in the examples before, we are looking for exact text in an exact location to confirm that the command has succeeded. In this case, we are looking for “Run succeed” in the 4th slot of the array of text that follows.

Add-PSSnapin McliPSSnapin
$diskInfo = Mcli-Get diskinfo -p deviceName=Device001 –f diskLocatorId
$diskID = $diskinfo[4]
$splitPosition = $diskID.IndexOf(“:”)
$diskID = $diskID.SubString($splitPosition + 2, $diskID.Length – ($splitPosition + 2))
Mcli-Run PromoteDiskVersion -p diskLocatorId=$diskID

Screen Shot 1


After prompting the disk, we can create a new maintenance disk as shown below. The code is also identicial, the difference being that we are using the MCli-RunWithReturn cmdlet instead and it is getting a type of CreateMaintenanceVersion. The success indication text is also slightly different as the screen show shows.

Add-PSSnapin McliPSSnapin
$diskInfo = Mcli-Get diskinfo -p deviceName=Device001 –f diskLocatorId
$diskID = $diskinfo[4]
$splitPosition = $diskID.IndexOf(“:”)
$diskID = $diskID.SubString($splitPosition + 2, $diskID.Length – ($splitPosition + 2))
Mcli-RunWithReturn CreateMaintenanceVersion-p diskLocatorId=$diskID

Screen Shot 2


With these pieces of code, you could then use SCORCH or some other orchestration method to hand off the updating of your images to lower level support staff if you so choose.

That’s it for the moment on PVS automation. Be sure to check out the posted slides for SYN514 which Paul and I presented at this year’s Synergy. It covered all the information that this 4 part series has covered plus a lot more.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">