Housekeeping Citrix App Layering Layers
Everyone who’s delivering changes knows that every and all changes should result in a new version or revision. This to keep track on what matter has been altered and provides the ability the revert to an prior release.
This article will be the first one of a series describing some of the automation scripts I’ve written to make my own and hopefully yours a bit more fun. I at least had lots of fun writing them.
Citrix App Layering & Revisions
For the ones of you who are working with Citrix App layering experienced that you might get lost on the number of revisions created for a certain layer. Administering the layers and their revisions can become challenging as the changes follow-up rapidly and eating your costly storage.
Houskeeping
Cleaning out obsolete images and layer revisions on the appliance make perfect sense because you don’t care about these any longer when newer versions went trough UAT successfully and being stamped ‘production’. You probably want to have at least one or two prior revisions available where you can rely on when things go wrong. Here again buddy PowerShell comes along.
Automation in general
The rule of thumb is that you should automate every task which has a repetitive character. For sure the ones where you don’t want to be bothered about and should be done during the dark hours for you making your life easier with more room for the fun stuff.
The story about (remotely) managing the layering appliance…
The Citrix app layering appliance currently does not come with the ability to manage it without using the webgui. But how wonder! There is a solution! Just like one of my prior posts the scripts for this article also fully rely on various command-lets from the awesome Reverse Engineered SDK created by Ryan Butler. I was happy to be able to contribute to enhance some of the functions to reach my goal on these housekeeping and maintenance script.
The two scripts covered in this article are;
- [1/2] CAL_PowerShell_SDK_Cleanup_Obsolete_Images
- [2/2] CAL_PowerShell_SDK_Cleanup_Obsolete_Revisions
Scripts Prerequisites:
- ctxal-sdk: As I already alluded to you’ll need the Citrix App Layering SDK for obvious reasons where can find the install instructions for here.
- LIC_Function_Library.psm1: A powershell module containing generic often used functions across different scripts. This one should be in the same locations as the scripts which calls it. Instructions here
[1/2] CAL_PowerShell_SDK_Cleanup_Obsolete_Images
Github: Find the script here.
User confirmation before deletion is enabled by default.

Purpose: Cleanup Images per ‘unique role’ and ‘revision number’ on the layering appliance skipping the last three (by default)
Example: CAL_PowerShell_SDK_Cleanup_Obsolete_Images.ps1 [-Environment {DTA|PROD}] [-Credential <$credential>]
Parameters:
- Environment: The parameter section for the script let you choose between two appliances. In my scenario I have a Development/Test/Acceptance (DTA) and a Prod appliance (PROD) to choose from. configurable in the script trough variables.
- Credential: The credential environment allow for a ‘PSCredential’ object as input or a username which presents a popup to provide the admin credentials to connect to the appliance with the appropriate permissions.
param( [parameter(Mandatory=$true)] [ValidateSet("DTA", "PROD")] $Environment = "DTA", # -> The environment to process, either DTA or PROD. [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty )
Variables:
- Skiplast: the number of images to keep
- DTAAppliance: The name of the Dev/Test/Acceptance appliance
- PRODAppliance: The name of the Production appliance
- ImageNameRegEx: RegEx filter to match a predefined naming convention for the image names like e.g. R_W10_DSK_IMG_R001
- Logpath: Provide the UNC path where to place the log file
# Variables $Skiplast = "3" $DTAApliance = "DTAAppliancehere" $PRODAppliance = "PRODAppliancehere" $ImageNameRegEx = "[SR]_[W]\d{2}_[A-Z]{3,5}_(IMG)_[R]\d{3}" $Logpath = "loguncpathhere"
workflow
- Validate provided credentials and connect to the appliance for the given environment
- Retrieve all images available on the appliance
- build array $my_match_list with all unique imagenames by excluding the revision from the name
- Build array $my_strings_list matching $imageNameRegEx
- Build array $selection which include the revisions for every item in $my_match_list excluding the last number represented by $Skiplast
- Remove each item in $selection
- disconnect from the appliance
[2/2] CAL_PowerShell_SDK_Cleanup_Obsolete_Revisions
Github: Find the script here.
User confirmation before deletion is enabled by default.

Purpose: Cleanup the three (by default) last layer revisions based on type (OS, App and Platform) name and ‘revision number’ which are currently not being assigned.
Example: CAL_PowerShell_SDK_Cleanup_Obsolete_Revisions.ps1 [-LayerType {OSLayer|AppLayer|PlatformLayer}] [-Environment {DTA|PROD}] [-Credential <pscredential>]
Parameters:
- LayerType: You need to specify the LayerType (OSLayer, AppLayer or PlatformLayer) to process. If you want to process all types you currently need to rerun the script with the LayerType of choice.
- Environment: The parameter section for the script let you choose between two appliances. In my scenario I have a Development/Test/Acceptance (DTA) and a Prod appliance (PROD) to choose from. configurable in the script trough variables.
- Credential: The credential environment allow for a ‘PSCredential’ object as input or a username which presents a popup to provide the admin credentials to connect to the appliance with the appropriate permissions.
param( # The LayerType to process, either OSLayer, PlatFormLayer or Applayer. [parameter(Mandatory=$true)] [ValidateSet("OSLayer", "PlatFormLayer", "AppLayer")] $LayerType, [parameter(Mandatory=$false)] [ValidateSet("DTA", "PROD")] $Environment = "DTA", [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty )
Variables:
- Skiplast: the number of Layer Revisions to keep
- DTAAppliance: The name of the Dev/Test/Acceptance appliance
- PRODAppliance: The name of the Production appliance
- Logpath: Provide the UNC path where to place the log file
# Variables $Skiplast = "3" $DTAApliance = "DTAAppliancehere" $PRODAppliance = "PRODAppliancehere" $Logpath = "loguncpathhere"
workflow
- Validate provided credentials and connect to the appliance for the given environment.
- Retrieve all layers available on the appliance for the provided type; OS, App or Platform
- Loop trough all retrieved layers running the following steps;
- Get the latest layer revisions for the given layer.
- Build array $AllAppLayerRevsCanDelete with layer revisions which can be deleted keeping the three most recent.
- Remove each item in $selection and verify that it was done.
- disconnect from the appliance