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:
Import-Module "C:\Program Files\Citrix\Provisioning Services Console\Citrix.PVS.SnapIn.dll"
When you have it loaded you can run this command to view what options you have:
Get-Command -Module Citrix.PVS.SnapIn
So to create a new device collection we first run:
Get-Help New-PvsCollection -Examples
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:
To create a new device collection called Citrixlab we can use this command with the information we just found:
New-PvsCollection -CollectionName "Citrixlab" -SiteName "Skanderborg"
Create a PVS target device
Going through the same process with creating a new device we get the following from the help:
New-PvsDevice -Name theDevice -DeviceMac "00-11-22-33-44-55" -SiteName theSite -CollectionName theCollection
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:
New-PvsDevice -DeviceName "Citrixlab-xa01" -DeviceMac "00-11-22-33-44-55" -CollectionName "Citrixlab" -SiteName "Skanderborg"
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”
New-PvsStore -StoreName "CitrixlabStore" -Path "D:\Stores\CitrixlabStore"
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.
Import-PVSVDisk -NewVDiskName "CitrixlabvDisk" -PVSStore "CitrixlabStore" -PVSServerName "PVS01" -PVSSiteName "Skanderborg" -VHDXPath "D:\Stores\CitrixlabStore"
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
Set-PVSVdiskProperties -PVSStore "CitrixlabStore" -PVSSite "Skanderborg" -VdiskName "CitrixlabvDisk" -CacheType CacheInRAMOverflowToDisk -LicenseType KMS -CacheSizeInMB 2048
Assign vDisk to device collection
To add a vDisk to a device collection we can use this simple command:
Add-PvsDiskLocatorToDevice -SiteName "Skanderborg" -StoreName "CitrixlabStore" -DiskLocatorName "CitrixlabvDisk" -CollectionName "Citrixlab" -RemoveExisting
Create new vDisk version
To create a new version of the vDisk to install patches and software on you can use the command below.
New-PvsDiskMaintenanceVersion -DiskLocatorName "CitrixlabvDisk" -SiteName "Skanderborg" -StoreName "CitrixlabStore"
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.
Invoke-PvsPromoteDiskVersion -DiskLocatorName "CitrixlabvDisk" -StoreName "CitrixlabStore" -SiteName "Skanderborg" -Test
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.
Invoke-PvsPromoteDiskVersion -DiskLocatorName "CitrixlabvDisk" -StoreName "CitrixlabStore" -SiteName "Skanderborg"
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.
$LocaterID = (Get-PvsDisk -DiskLocatorName "CitrixlabvDisk" -SiteName "Skanderborg" -StoreName "CitrixlabStore").DiskLocatorId Remove-PvsDiskLocator -DiskLocatorId $LocaterID -DeleteDiskFile
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:
Remove-PvsDevice -DeviceName "Citrixlab-XA01"
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
Remove-PvsCollection -CollectionName "Citrixlab" -SiteName "Skanderborg"
I hope that this article is useful for you and please provide any feedback you might have.