Script to update the XenDesktop MCS Pooled VDI.

Rad DavidPrincipal Project Manager
CERTIFIED EXPERT
Published:
This article describes how to update the XenDesktop Master Image Pooled machine types using PowerShell.

These commands are tested on XenDesktop 5.6 and VMware environment.

Like I said in my pervious article, “PowerShell is a very powerful scripting language that can help automate many aspects of maintaining and deploying a XenDesktop environment.”  This saves a lot of time for the Citrix administrators.

Whenever we run a powershell script or command first thing that we should do is to load the Citrix Snapins. If you do not have the Citrix snapins download it from  http://www.citrix.com/downloads

Asnp Citrix.*
                      

Open in new window

This loads the Citrix-specific PowerShell modules. (Asnp means Add-PSSnapin).

Now let’s go with the steps to update the MCS Catalog with the updated master image.

Step 1: Modify the Master Virtual Machine or new virtual machine with the required changes.

Step 2: Take a snapshot of the modified virtual machine. 

New-HypVMSnapshot this command provides a mechanism for creating a new snapshot of a virtual machine given a Host Service provider path to a VM.
 
New-HypVMSnapshot -AdminAddress $XDServername -LiteralPath 'XDHyp:\VMPATH\VMNAME.vm' -SnapshotName "$filename" -SnapshotDescription "$description" 
                      

Open in new window

Step 3: Now to update the Catalog with the latest snapshot that was taken in the Step 2.  To get the last snapshot name use the command  Get-ChildItem using the following syntax:
 
(Get-ChildItem -Recurse -path 'XDHyp:\HostingUnits\Path of the MasterImage.vm').PSPath 
                      

Open in new window


This command will list all the snapshots that are taken for the master VM.
To get the path of the Master VM use the command mentioned on Step 4.

Step 4: To get the Provisioning schema name, ProvisioningSchemeUid and the Master Image VM Path use the  provscheme command. This command lets you retrieve the list of defined provisioning schemes.
 
provscheme -AdminAddress ‘$XDServerName’
                      

Open in new window


Step 5: Update the pooled catalog with the new master image using the command  Publish-ProvMasterVmImage along with the Provisioning scheme Uid and the Master Image VM path, this command updates the master image associated with the provisioning scheme.
 
Publish-ProvMasterVmImage -AdminAddress ‘XDServername’ -ProvisioningSchemeUid 'Value’ -MasterImageVM ‘$VMname’
                      

Open in new window


Using all the above mention commands we will build a script to update the Pooled desktop.

To take the snapshot of the master image
 
#To take the snapshot of the master image
                      #Load The Citrix Snapins
                      
                      Asnp Citrix.*
                      
                      #Declare the variables
                      
                      $XDserver = "Server Name"
                      $filename = "MasterImage_Snapshot_$(get-date -f MMM-d-yyyy-hh-mm)"
                      $description = "MasterImage_Sanpshot_$(get-date -f MMM-d-yyyy-hh-mm)"
                      
                      # To take Snapshot of the Master VDI
                      
                      New-HypVMSnapshot -AdminAddress '$XDserver' -LiteralPath 'XDHyp:\connections\Path of the VM\VMNAME.vm' -SnapshotName "$filename" -SnapshotDescription "$description" 
                      

Open in new window


 To Update the Pooled Catalog

#To update the Pooled Catalog
                      
                      #Add the Citrix snap-ins
                      
                      Asnp Citrix.*
                      
                      #Variables declaration
                      $XDserver = "Server Name"
                      $ProvisioningSchemeUid = “ProvisioningSchemeUid”
                      
                      #To get the Snapshot details - with the hosting unit
                      (Get-ChildItem -Recurse -path 'XDHyp:\Path\VMName.vm').PSPath > 'C:\temp\Snapshotdetails.txt'
                      $Snapshot = @(gc "C:\temp\Snapshotdetails.txt" | Select-Object -last 1)
                      $Snapshot = $Snapshot.trimstart("Citrix.Host.Admin.V1\Citrix.Hypervisor::")
                      
                      # Update the Master Image details and update the catalog
                      Publish-ProvMasterVmImage -AdminAddress "$XDserver" -ProvisioningSchemeUid ‘$ProvisioningSchemeUid' -MasterImageVM $Snapshot
                      

Open in new window


Step 6: Reboot all the Pooled VDIs after the update is complete

Tested Environment
XenDesktop 5.6, PowerShell 3.0, Windows 7
0
2,488 Views
Rad DavidPrincipal Project Manager
CERTIFIED EXPERT

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.