{"id":3808,"date":"2012-06-13T12:20:34","date_gmt":"2012-06-13T10:20:34","guid":{"rendered":"https:\/\/ingmarverheij.com\/?p=3808"},"modified":"2012-06-13T12:36:06","modified_gmt":"2012-06-13T10:36:06","slug":"set-citrix-policies-via-powershell","status":"publish","type":"post","link":"https:\/\/ingmarverheij.com\/en\/set-citrix-policies-via-powershell\/","title":{"rendered":"Set Citrix policies via PowerShell"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"left\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/XenApp-Configure-Access.png\" width=\"101\" height=\"92\" \/><\/p>\n<p>Since Citrix XenApp 6.0 and XenDesktop 5.0 policies are configurable via a new method. As a bonus Citrix made it possible to configure the policies via Group Policy Objects (GPO\u2019s) in Active Directory. <\/p>\n<p>This is especially useful if you want to set Citrix policies unattended, or automated. This way you can use it in a deployment or incorporate it in your own (provisioning) tool.<\/p>\n<p>In this article I\u2019ll explain how you can set Citrix XenApp 6.5 policies in a GPO via a PowerShell script from a remote machine. You can execute the commands from any domain joined machine, there\u2019s no need to execute the script from a Citrix server or Active directory Domain Controller.<\/p>\n<p><!--more--><\/p>\n<p>&#160;<\/p>\n<h2>Prerequisites<\/h2>\n<p>The Citrix policies in a Group Policy Object (GPO) are configured in a custom interface, supplied by Citrix during installation of XenApp 6.5. To configure the policies from PowerShell the XenApp 6.5 PowerShell SDK needs to be installed on the machine where you\u2019ll be executing the script.<\/p>\n<p>The XenApp 6.5 PowerShell SDK can be downloaded <a href=\"https:\/\/community.citrix.com\/display\/xa\/XenApp+6.5+Powershell+SDK\">here<\/a>. I found out it is necessary to execute the installer with elevated rights (Run as Administrator), otherwise no dialog where shown.<\/p>\n<p>Secondly you need the PowerShell module <a href=\"https:\/\/community.citrix.com\/download\/attachments\/162955822\/Citrix.GroupPolicy.Commands.psm1?version=1\">Citrix.GroupPolicy.Commands.psm1<\/a> (supplied by Citrix) that contains some wrappers around policies. More information about the module can be read <a href=\"https:\/\/community.citrix.com\/display\/xa\/Exporting+and+Importing+XenApp+Group+Policies\">here<\/a>.<\/p>\n<p>&#160;<\/p>\n<h2>Preparation<\/h2>\n<p>First we need to load the module (<a href=\"https:\/\/community.citrix.com\/download\/attachments\/162955822\/Citrix.GroupPolicy.Commands.psm1?version=1\">Citrix.GroupPolicy.Commands.psm1<\/a>) in the PowerShell script so we can use the functions.<\/p>\n<pre lang=\"ps\">#Import module\nImport-Module .\\Citrix.GroupPolicy.Commands<\/pre>\n<p>And add the PowerShell snap-ins from the PowerShell SDK<\/p>\n<pre lang=\"ps\">#Add PowerShell snapins (if necessary)\nif ( (Get-PSSnapin -Name Citrix.Common.GroupPolicy -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Citrix.Common.GroupPolicy }\nif ( (Get-PSSnapin -Name Citrix.Common.Commands -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Citrix.Common.Commands }\nif ( (Get-PSSnapin -Name Citrix.XenApp.Commands -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Citrix.XenApp.Commands }<\/pre>\n<p>Now we can connect an object to a Group Policy Object (GPO) to a <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dd315340.aspx\">Windows PowerShell drive<\/a>. <\/p>\n<pre lang=\"powershell\">#Connect PowerShell drive to Citrix domain GPO\nNew-PSDrive -Name CitrixGPO -PSProvider CitrixGroupPolicy -Root \\ -DomainGPO &quot;Citrix GPO&quot; <\/pre>\n<p>In this example I connect the Windows PowerShell drive <em>CitrixGPO.<\/em>to the domain GPO \u201cCitrix GPO\u201d. <\/p>\n<p><em>NOTE: The examples found in the XenApp 6.5 PowerShell SDK referers to the \u2013FarmGPO setting. This setting connects the Windows PowerShell drive to the policy in the farm (instead of a Active Directory GPO) but can only be used from a Citrix XenApp system, not from a remote machine.<\/em><\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Citrix-GPO.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Citrix-GPO_thumb.png\" width=\"604\" height=\"312\" \/><\/a><\/p>\n<p>After your done with setting Citrix policies you need to remove the Windows PowerShell drive with this command.<\/p>\n<pre lang=\"powershell\">#Close PowerShell Drive from Citrix domain GPO\nRemove-PSDrive -Name CitrixGPO<\/pre>\n<p>&#160;<\/p>\n<h2>Reading and writing policy objects<\/h2>\n<p>Multiple Citrix policy objects can reside in a Active Directory Group Policy Object. By default there are two 1) a Computer policy object named \u201cUnfiltered\u201d and 2) a User policy object named \u201cUnfiltered\u201d. <\/p>\n<h4>&#160;<\/h4>\n<h4>Reading<\/h4>\n<p>In order to change the setting of a policy object you need to read the content of the policy object.<\/p>\n<pre lang=\"powershell\">#Read Citrix user policy\n$objCitrixPolicy = Get-CtxGroupPolicyConfiguration -PolicyName &quot;Unfiltered&quot; -Type user -DriveName CitrixGPO<\/pre>\n<p>In this example I read the content of the \u201c<strong>Unfiltered<\/strong>\u201d policy object of the <strong>User <\/strong>configuration from the drive <strong>CitrixGPO<\/strong> and place it in the <strong>$objCitrixPolicy<\/strong> variable.<\/p>\n<h4>&#160;<\/h4>\n<h4>Writing<\/h4>\n<p>After you\u2019ve set the settings in the policy object it need to be written to the Active Directory Group Policy Object.<\/p>\n<pre lang=\"PowerShell\">#Write Citrix user policy\nSet-CtxGroupPolicyConfiguration $objCitrixPolicy -DriveName CitrixGPO<\/pre>\n<p>In this example I wrote the content of the <strong>$objCitrixPolicy <\/strong>variable to the <strong>CitrixGPO <\/strong>drive.<\/p>\n<p>&#160;<\/p>\n<h2>Group Policy Settings<\/h2>\n<p>The settings in the policy objects that can be configured can be found in the Citrix XenApp 6.5 Commands Reference (found in the start menu after installing the XenApp 6.5 PowerShell SDK). Here you\u2019ll find an item called Group Policy Settings with two nodes: Computer Settings and User Settings.<\/p>\n<p>All settings that can be configured in a GPO can be found here, including the values you can set. Mainly there are two type of settings, boolean data types and non-boolean data types.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Client-drive-redirection.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Client-drive-redirection_thumb.png\" width=\"119\" height=\"69\" \/><\/a>Boolean data types, like ClientDriveRedirection, are either Allowed or Prohibited. These settings are configured by setting the State object to Enabled or Disabled.<\/p>\n<pre lang=\"PowerShell\">$objCitrixPolicy.(&quot;ClientDriveRedirection&quot;).State = &quot;Enabled&quot;<\/pre>\n<p>&#160;<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/AudioQuality.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/AudioQuality_thumb.png\" width=\"119\" height=\"64\" \/><\/a>Non-boolean data types, like AudioQuality, have multiple values that can be chosen from a dropdown box. These settings are configured by setting State to Enabled and filling the Value field with the appropriate setting which can be found in the Commands Reference.<\/p>\n<pre lang=\"PowerShell\">$objCitrixPolicy.(&quot;AudioQuality&quot;).State = &quot;Enabled&quot;\n$objCitrixPolicy.(&quot;AudioQuality&quot;).Value = 2<\/pre>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Group-Policy-Settings-User-Settings-AudioQuality.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/Group-Policy-Settings-User-Settings-AudioQuality_thumb.png\" width=\"119\" height=\"67\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/AudioQualityOption-Enumeration.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/AudioQualityOption-Enumeration_thumb.png\" width=\"119\" height=\"67\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p>If you\u2019re not sure if this is a Boolean data type or not, just check if the Value property equals Null.<\/p>\n<pre lang=\"PowerShell\">#Set policy setting\nIf ($objCitrixPolicy.(&quot;SETTING&quot;).Value -ne $null)\n{\n   $objCitrixPolicy.(&quot;SETTING&quot;).Value = &quot;VALUE&quot;\n   $objCitrixPolicy.(&quot;SETTING&quot;).State = &quot;Enabled&quot;\n} else \n{\n   $objCitrixPolicy.(&quot;SETTING&quot;).State = &quot;VALUE&quot;\n}<\/pre>\n<p>Where SETTING equals the user\/computer setting you want to set and VALUE the value of the setting <img decoding=\"async\" style=\"border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none\" class=\"wlEmoticon wlEmoticon-winkingsmile\" alt=\"Knipogende emoticon\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/06\/wlEmoticon-winkingsmile.png\" \/><\/p>\n<p>&#160;<\/p>\n<h2>Clear all existing settings<\/h2>\n<p>If you want to clear all existing settings in a policy object you can use this script:<\/p>\n<pre lang=\"PowerShell\">#Clear all existing settings\nforeach ($objCitrixPolicyProperty in @($objCitrixPolicy | Get-Member -Type Properties | Select -Expand Name))\n{\n   $config = $objCitrixPolicy.$objCitrixPolicyProperty\n   if ($config.State -ne $null) { $objCitrixPolicy.($objCitrixPolicyProperty).State = &quot;NotConfigured&quot; }\n}<\/pre>","protected":false},"excerpt":{"rendered":"<p>Since Citrix XenApp 6.0 and XenDesktop 5.0 policies are configurable via a new method. As a bonus Citrix made it possible to configure the policies via Group Policy Objects (GPO\u2019s) in Active Directory. This is especially useful if you want to set Citrix policies unattended, or automated. This way you can use it in a [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[305,54],"tags":[667,459,458,455,672],"class_list":["post-3808","post","type-post","status-publish","format-standard","hentry","category-xenapp-presentation-server","category-xendesktop","tag-citrix","tag-gpo","tag-policies","tag-posh","tag-powershell"],"_links":{"self":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/comments?post=3808"}],"version-history":[{"count":4,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3808\/revisions"}],"predecessor-version":[{"id":3812,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3808\/revisions\/3812"}],"wp:attachment":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/media?parent=3808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/categories?post=3808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/tags?post=3808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}