Saturday, January 25, 2014

How to Import and Export Policies in XenApp 6.x

Summary
This article describes how to import and export XenApp 6 & XenApp 6.5 policies stored as Active Directory (AD) Group Policy Objects (GPO), as local server policies (Local Server Policy), and policies in the IMA Datastore (Farm Policy).
Background
XenApp administrators need the permission to import and export Citrix policies. Use cases might include disaster recovery, configuring lab environments, deploying local server policies to individual server, and rapid staging of new Active Directory policies.
Requirements & Preparation
  1. Download and install the appropriate Citrix XenApp SDK (from the links below) on one of the XenApp servers in your farm.
    - Citrix XenApp 6 SDK
    - Citrix XenApp 6.5 SDK
  2. Download the Citrix.GroupPolicy.Commands.psm1 module to a local drive on the XenApp server that has the SDK installed. The powershell script is also available as part of Citrix Scout: http://support.citrix.com/article/CTX130147
  3. Download and Extract Scout.zip
  4. Navigate to the Current\Utilities Subfolder
  5. Copy the Citrix.GroupPolicy.Commands.psm1 from the Utilities folder

  1. On the XenApp server, launch Windows PowerShell with Citrix XenApp Server SDK (from Start > All Programs > Citrix > XenApp Server SDK).


  1. At the PowerShell prompt, run the following command:
    import-module <Path To Citrix.GroupPolicy.Commands.psm1>
    Note
    : If prompted, type R for "Run once".


*If this completes successfully, please continue to the Procedure section below to begin importing and exporting your policies.
Note: In some instances you may receive an error message stating “The file C:\GroupPolicy.Commands.psm1 is not digitally signed. The script will not execute on the system”. (As seen below)

  1. Run the following command to fix the issue:
    set-executionpolicy unrestricted –force
  2. Now try to import the Citrix.GroupPolicy.Commands again:
    import-module <Path To Citrix.GroupPolicy.Commands.psm1>
    Note: If prompted, type R for "Run once".

*If this completes successfully, please continue to the Procedure section below to begin importing and exporting your policies.
*If you continue to experience issues with importing the Group Policy Commands due to the Citrix.GroupPolicy.Commands.psm1 file not be trusted, then run the following command to get more help on the issue: get-help about_signing

Procedure - Importing and Exporting Policies

IMA Datastore Farm Policy
Exporting from IMA Datastore Farm Policy
Unless a PowerShell drive is specified, the Export-CtxGroupPolicy cmdlet defaults the IMA Datastore Farm Policy. Run the following command to export from the IMA Datastore:
Export-CtxGroupPolicy <PathToExportFolder>

Importing to IMA Datastore Farm Policy
Unless a PowerShell drive is specified, the Import-CtxGroupPolicy cmdlet defaults the IMA Datastore Farm Policy. Run the following command to import to the IMA Datastore:
Import-CtxGroupPolicy <PathToExportFolder>

Local Server Policy
Exporting from Local Server Policy
Unless a PowerShell drive is specified, the Export-CtxGroupPolicy cmdlet defaults the IMA Datastore Farm Policy. Run the following command to export from the local server policy:
Export-CtxGroupPolicy –DriveName localgpo <PathToExportFolder>

Importing to Local Server Policy
Unless a PowerShell drive is specified, the Import-CtxGroupPolicy cmdlet defaults the IMA Datastore Farm Policy. Run the following command to import to the local server policy:
Import-CtxGroupPolicy <PathToExportFolder> –DriveName localgpo

Active Directory Policy
Exporting from Active Directory GPO
1. Associate a new PowerShell drive to the GPO to be exported. In this example, replace <DomainGpoDrv> with the name of the new PowerShell drive being created and replace <DomainGPO> with the display name of the Active Directory GPO to be exported.
New-PSDrive -Name <DomainGpoDrv> -PSProvider CitrixGroupPolicy -Root \ -DomainGpo <DomainGPO>
Note
: The new PowerShell drive is a non-persistent drive that is used only within the session.

2. Export the GPO to a folder:
Export-CtxGroupPolicy -DriveName <DomainGPODrv> <PathToExportFolder>
 

Importing to Active Directory GPO
1. Associate a new PowerShell drive to the GPO to be exported. In this example, replace <DomainGpoDrv> with the name of the new PowerShell drive being created and replace <DomainGPO> with the name of the Active Directory GPO being exported.
Note
: The target GPO must already exist in the Active Directory domain. The new PowerShell drive is a non-persistent drive that is used only within the session.
New-PSDrive -Name <DomainGpoDrv> -PSProvider CitrixGroupPolicy -Root \ -DomainGpo <DomainGPO>

2. Import the GPO from a folder:
Import-CtxGroupPolicy <PathToExportFolder> -DriveName <DomainGPODrv>