View RSS Feed


Documenting Citrix with PowerShell: Citrix Policies

Rating: 3 votes, 4.67 average.
Documentation is a vital (yet rarely loved) part of systems administration/engineering. Exhaustively documenting Citrix can turn your hair white. There are farm-wide settings, polices, application publishing properties, zone configuration, and that’s just the beginning.

We are in the midst of architecting a new Citrix environment where I work and we are taking advantage of this to review everything we have done before and changing it if needed. We’re also attempting to document every facet of our new environment which includes, Provisioning (DHCP), XenApp, XenServer, XenDesktop, AppSense, Netscalers, Web Interface, and MS App-V.

For this post, I’m providing a PowerShell script I modified from Kent Finkle that will capture a Citrix Policy and what it’s applied to in a Word document. The script will also export the Citrix policy and its filter (what it’s applied to) to 2 XML files that can be used to recreate or restore the configuration if it’s lost.
NOTE: This script assumes that the XenApp PowerShell Commands are installed on the server you’re running the script from. You can download them from

Here’s the script (download link at end of post):

#================================================= ========= #
# NAME: get-citrixpolicy.ps1
# AUTHOR: Alain Assaf
# DATE : 5/11/2010
# SOURCE: Author: Kent Finkle
# COMMENT: Output a Citrix Policy to a Word document.
# Assumes XenApp Commands are installed on source server
# VERSION: 1.0.0 – Initial script
# VERSION: 1.0.5 – Added policy filter and xml export of policy and filter
#================================================= =========

#Load XenApp Commands
Add-PSSnapin Citrix.XenApp.Commands

#Set variables
$docpath = “\Architecture\Citrix\policies”
$hname = $env:computername
$uname = $env:username
$a = get-date –format g
$b = get-date -uformat “%m%d%Y”

#Test path & create if not present
if (!(Test-path -path $docpath)) { new-item $docpath -type directory | out-null }

$objWord = New-Object -comobject Word.Application
$objWord.Caption = “Test Caption”
$objWord.Visible = $True

$farm = get-xafarm

$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objSelection.Font.Name = “Arial”
$objSelection.Font.Size = “18″
$objSelection.TypeText(“Citrix Policy Report”)
$objSelection.TypeText(” for Farm: ” + $farm.FarmName)
$objSelection.Font.Size = “8″
$objSelection.Font.Italic = $True
$objSelection.TypeText(“Script run on: ” + $hname)
$objSelection.TypeText(” by: ” + $uname)
$objSelection.TypeText(” at ” + $a)
$objSelection.Font.Italic = $False

$objSelection.Font.Size = “10″
$policy = Get-XAPolicyConfiguration -PolicyName $polname
$objSelection.Font.Bold = $True
$objSelection.TypeText(“Citrix Policy: ” + $policy.PolicyName)
$objSelection.Font.Bold = $False
$objSelection.Font.Size = “10″

$outpol = $policy | Out-String
$objSelection.TypeText(“” + $outpol)

$policyfilter = Get-XAPolicyFilter -PolicyName $polname
$objSelection.Font.Bold = $True
$objSelection.TypeText($policyfilter.PolicyName + ” policy applied to:”)
$objSelection.Font.Bold = $False
$objSelection.Font.Size = “10″

$outpolfilter = $policyfilter | Out-String
$objSelection.TypeText(“” + $outpolfilter)

$doctitle = $farm.FarmName + “_” + $policy.PolicyName + “_” + $b
$objDoc.SaveAs([ref] “$docpath\$doctitle.doc”)

$poltitle = $farm.FarmName + “_” + $policy.PolicyName + “_Policy” + “_” + $b
$polfiltertitple = $farm.FarmName + “_” + $policyfilter.PolicyName + “_PolicyFilter” + “_” + $b

export-clixml -path “$docpath\$poltitle.xml” -InputObject $policy
export-clixml -path “$docpath\$polfiltertitple.xml” -InputObject $policyfilter

Here’s a sample of the Word document (sanitized for public consumption):

The intention is to run this script periodically to provide documentation and a backup of all the policies applied to a farm. I encourage you to explore the PowerShell commands provided by Citrix. You will be able to document every aspect of your farm and also have an easy way to backup/restore the information as needed.

Script is available below.

Attached Thumbnails Attached Files

Updated 05-26-2010 at 02:53 PM by alainassaf

Tags: None Add / Edit Tags


  1. murtymnv's Avatar
    ps>set-executionpolicy unrestricted