With the acquisition of RingCube last August, Citrix’s XenDesktop 5.6 has added two new Catalog types (PvD and PvsPvD) to be used with pooled static desktops. These catalog types pertain to attaching Personal vDisks (PvD) to the virtual machines.

This article will focus mainly on using PowerShell to create a PvD catalog with Machine Creation Service (MCS). If you would like an overview of Personal vDisk technology, you can find it here. Also this article is mostly for PowerShell enthusiasts. Alternatively you can use XenDesktop wizards to create PvD desktops.

If you are familiar with XenDesktop snapins for Powershell, you will find that creating a PvD catalog is fairly simple. There are mainly 3 necessary changes. (If you first want to familiarize yourself with XenDesktop PowerShell SDK for creating catalogs, check out this blog post).

Provisioning Scheme Changes

For PvD, when creating a new provisioning scheme you have to specify the -UsePersonalVDiskStorage option. If you use this option you will also have to specify the size of PvD disk (with -PersonalVDiskDriveSize option) and the drive letter that PvD disk will consume inside each VM (with PersonalVDiskDriveLetter option).

$provScheme = New-ProvScheme -ProvisioningSchemeName $provSchemeName -HostingUnitName $hostingUnitName -MasterImageVM $baseImageSnapshot -IdentityPoolName $idPoolName -CleanOnBoot -UsePersonalVDiskStorage -PersonalVDiskDriveLetter $PvDDriveLetter -PersonalVDiskDriveSize $PvDDisksize

Catalog Creation Changes

The second change is while creating the catalog itself. One point to note is that PvD can only be used with pooled static desktops and hence the AllocationType (while creating the catalog) can only be “Permanent”. Along with this, as shown below there is a new value added for CatalogKind to create a Pvd Catalog on MCS.

$bdc = New-BrokerCatalog -Name $catalogName -AllocationType Permanent -CatalogKind Pvd -PvsForVM "$($provScheme.ProvisioningSchemeUid):$($provScheme.HostingUnitUid)"

Catalog Preparation Changes

After the catalog has been created with the PvD disks attached to the VM, the broker has to be informed to prepare each attached disk for use with the PvD technology by calling Start-BrokerCatalogPvdImagePrepare API.

Script

The script creates a PvD catalog that leverages MCS. The script has some setup parameters that have to be configured for your environment.

# -----------------------------------------------------------------------------
# * Install the Citrix SDK PowerShell snap-ins:
Add-PSSnapin Citrix.ADIdentity.Admin.V1
Add-PSSnapin Citrix.Broker.Admin.V1
Add-PSSnapin Citrix.Configuration.Admin.V1
Add-PSSnapin Citrix.MachineCreation.Admin.V1
Add-PSSnapin Citrix.Host.Admin.V1
Add-PSSnapin Citrix.MachineIdentity.Admin.V1

# -----------------------------------------------------------------------------
# * Setup parameters
$desktopGroupName = "Desktop Group" # Desktop Group to Use
$hostingUnitName = "hostingunit"
$brokerhypervisorConnection = "hyp-name"
$provSchemeName = "PVD-PS" # A PVD prov-scheme
$catalogName = "PvD-Catalog"
$baseImageSnapshot = "'XDHyp:\hostingunits\XenHU1\Win7.SP1.x86.P1 (1).vm\Win7SP1x86P1_snapshot.snapshot'"
$idPoolName = "IdPoolPVD" $suffix = "Suffix"
$count = 70 # number of desktops to create

# -----------------------------------------------------------------------------
# * Get the broker connection
$bhc = Get-BrokerHypervisorConnection -Name $brokerhypervisorConnection
"Broker hypervisor connection"
$bhc

# -----------------------------------------------------------------------------
# * Create Id Pool
# Where in the domain you want the computer accounts for provisioned VDA(s) to go
$adContainerOU = "Container"
$d = GetDomain "LDAP Domain: " + $domain
$adContainerDN = "OU=Computers,OU="+$adContainerOU+","+$d.distinguishedName

# -----------------------------------------------------------------------------
# Names of the provisioned PvD VDA(s)
$adAccountNameSpecification = "CDN-"+ $suffix + "-####"
$adAccountPool = New-AcctIdentityPool -IdentityPoolName $idPoolName -NamingScheme $adAccountNameSpecification -NamingSchemeType Numeric -Domain $domain -OU $adContainerDN
"Account Identity Pool:" $adAccountPool

# -----------------------------------------------------------------------------
# * Create a single new adAccount
$result = New-acctADAccount -IdentityPoolName $idPoolName -Count $count
$newAccount = $result.SuccessfulAccounts
"New account:"
$newAccount

# ----------------------------------------------------------------------------
# * Create provisioning scheme (this is a time-consuming step as it involves fully duplicating the base image):
# (you can monitor progress by going to the console of the hypervisor host
#
# If you use XenServer go to the console of the hypervisor in XenCenter and use the command
# xe task-list
# ... there should be a task entitled Async.VDI.copy - the progress field will increase from
# 0.000 to 1.000 as the task progresses.
# Notice for PvD, while creating a new provisioning scheme we use the parameters UsePersonalVDiskStorage,
# PersonalVDiskDriveLetter and PersonalVDiskDriveSize. These parameters are to attach a PvD disk to the
# virtual machines and to specify the size and drive letter of the PvD Disk.
Write-Host "Creating PVD provisioning scheme with: `nDisk size= $PvDDisksize GB `nDrive Letter $PvDDriveLetter `nIdentity pool $idPoolName"

# -----------------------------------------------------------------------------
# example : New-ProvScheme -ProvisioningSchemeName 'pvdCatalog_XenHU1' -HostingUnitName 'XenHU1'-MasterImageVM 'XDHyp:\hostingunits\XenHU1\Win7.SP1.x86.P1 (1).vm\Win7SP1x86P1_snapshot.snapshot' -IdentityPoolName 'pvdCatalog' -VMCpuCount 1 -VMMemoryMB 1024 -CleanOnBoot -UsePersonalVDiskStorage -RunAsynchronously -PersonalVDiskDriveLetter E -PersonalVDiskDriveSize 5

$provScheme = New-ProvScheme -ProvisioningSchemeName $provSchemeName -HostingUnitName $hostingUnitName -MasterImageVM $baseImageSnapshot -IdentityPoolName $idPoolName -CleanOnBoot -UsePersonalVDiskStorage -PersonalVDiskDriveLetter $PvDDriveLetter -PersonalVDiskDriveSize $PvDDisksize

"Provisioning Scheme"
$provScheme

# -----------------------------------------------------------------------------
# BrokerCatalog (PvDisk) is created here so that desktop studio can find which provisioning schemes are used
# for a particular catalog.
# PvsForVms takes $provScheme.HostingUnitUid, $provScheme.ProvisioningSchemeUid
# Notice for PvD we use AllocationType as Parmanent and CatalogKind as PvD for creating a MCS PvD catalog
$bdc = New-BrokerCatalog -Name $catalogName -AllocationType Permanent -CatalogKind Pvd -PvsForVM "$($provScheme.ProvisioningSchemeUid):$($provScheme.HostingUnitUid)"

"Broker Catalog:"
$bdc

"Prepare catalog $($bdc.UiD) for PVD images."
Start-BrokerCatalogPvdImagePrepare -inputobject $bdc.UiD

$newVMs = New-ProvVM -ProvisioningSchemeName $provSchemeName -ADAccount @($newAccount)

if($newVMs.VirtualMachinesCreationFailedCount -gt 0)
{
    "Failed Virtual Machines"
    $newVMs.FailedVirtualMachines
    throw "FAILED: VirtualMachinesCreationFailedCount > 0 -- provisioning FAILED"
}

if($newVMs.VirtualMachinesCreatedCount -eq 0)
{
    throw "FAILED: VirtualMachinesCreation process failed, there are no virtual machines created."
}

# -----------------------------------------------------------------------------
# output additional information for debugging "Created Virtual Machines:"
# there should only ever be 1 provisioned VM per base image for the bvt, but loop for completeness to catch bugs

foreach ($provVm in $newVMs.CreatedVirtualMachines)
{
    $provVm
    $bpm = New-BrokerMachine $provVm.AdAccountSid -CatalogUid $bdc.Uid -HypervisorConnectionUid $bhc.Uid -HostedMachineId $provVm.VMId
    Add-BrokerMachine $bpm -DesktopGroup $bdt
    Lock-ProvVM -ProvisioningSchemeName $provSchemeName -VMId $provVM.VMId -Tag Brokered
}