Citrix PVS and PowerShell

Hi all

Today’s post is about Citrix PVS (PVS) and Powershell. This combination has been a pretty awful experience for a long time, but now things a looking up. Since PVS version 7.1x where Citrix released a Powershell module instead of MCLI commands we have been able to use some real powershell commands and logic. In this article I will show you how to do commen PVS task with powershell.

The tasks I want to show in this article are the following:

  • Create device collection
  • Create device
  • Import vdisk
  • Set vdisk properties
  • Assign vdisk
  • Create new vdisk version
  • Promote vdisk
  • Delete vDisk from store
  • Delete a device
  • Delete a device collection

Information used throughout the article

Device collection: CitrixLab

Device name: Citrixlab-XA01

Mac address: 00:11:22:33:44:55

Site name: Skanderborg

vDisk name: CitrixlabvDisk

Store name: CitrixlabStore

Create PVS device collection

So lets us start from the top and work our way through this. The first thing we need to do is import the module into our powershell session, this is done with the following command:

When you have it loaded you can run this command to view what options you have:

So to create a new device collection we first run:

2018-04-01_20-52-53

This will provide us with the information we need to create the new device collection. From the help we can see that the minimum information we need to provide is a name for the collection along with the siteID. So the name is something we can decide, but the siteID is something we need to find. Finding the SiteID is easy, we just use the command

In my lab this looks like this:

2018-04-01_20-54-31

To create a new device collection called Citrixlab we can use this command with the information we just found:

2018-04-01_21-00-06

 

Create a PVS target device

Going through the same process with creating a new device we get the following from the help:

So if we have a device with a Mac address of 00:11:22:33:44:55 we can add it to the PVS configuration with this command:

Do notice the format that the Mac address needs to be in.

Create PVS Store

To create a a new PVS store we can use the command below, this will create a new store called “CitrixlabStore” and it has the path of “D:\Stores\Citrixlab”

Importing vDisk

Next up is importing a vDisk into PVS.

To import a new vDisk into PVS I have create a small PowerShell module because I didn’t think the built in options was clear to use. I ended up with what I think is a pretty simple command which is shown below.

To explain what happens in the code above I will go through flow that is needed to execute the code. The first thing I needed to find was the information about the vhdx I wanted to import, this information I need is, disk size, creation date, name and last write date. With these information I can go ahead and create a new XML document that allows me to import the disk into PVS, this is the step i feel is missing from the built in commands for PVS because they assume that the XML file is present already which they never are when I import vDisks. Now that we have the XML document we need I can use the built in command for importing but to make it easy for everyone who wants to use my module I put that into my module as well so execution the command I showed will do all the work needed. The PowerShell module will be uploaded to the PowerShell gallery soon so it should be there when you read this article.

Setting vDisk properties

In the same PowerShell module that I have used to import vDisks into PVS I have also added a Set-PVSVdiskProperties command that for me makes it easier to set the properties needed on the vDisk. These properties are for instance licensing and cache type. Below is an example of how to use the command

Assign vDisk to device collection

To add a vDisk to a device collection we can use this simple command:

Create new vDisk version

To create a new version of the vDisk to install patches and software on you can use the command below.

Promote vDisk version

When you have installed your software and patches on the new vDisk version you can use the following command to put it into test mode.

When you have tested your new vDisk version and want to put it into production you can use the following command. Notice the only difference is the “-Test” that is on the command to put the vDisk into test mode.

Delete vDisk from store

If you want to delete a vDisk from your store you need to find the disk locator id and then you can remove it. The code to obtain that is shown below.

Note that if you do NOT want to delete the VHDX from your store just remove the “-DeleteDiskFile” from the commandline.

Delete a device

To delete a device is really simple as well, again I have used the help for find the parameters, so if we want to delete the device we just created we can do it like this:

Delete a device collection

To delete a device collection you need to specify the collection name or id along with either the siteID or the sitename. An example of this is shown below

I hope that this article is useful for you and please provide any feedback you might have.

 

/Martin Therkelsen

 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.