Citrix: Backup your Citrix policies with the SDK and Powershell

I had to create a script to backup the Citrix policies, in order to do this I had to use the Citrix.GroupPolicy.Commands.psm1. Before I could use them I had to install the XenApp SDK, because I had to run this script from every Citrix XA server I wanted to create an unattended install of the SDK.  I added a zipfile with the extracted XASD60.exe here.

 

To install the SDK unattended you case use the following command line:

msiexec /i %systemdrive%:\XASDK60\XASDK6.0\Setup\Citrix.Common.Commands.Install_x64.msi /qn
msiexec /i %systemdrive%\XASDK60\XASDK6.0\Setup\Citrix.XenApp.Commands.Install_x64.msi /qn
msiexec /i %systemdrive%\XASDK60\XASDK6.0\Setup\Citrix.XenApp.Server.SDK_x64.msi /qn
msiexec /i %systemdrive%\XASDK60\XASDK6.0\Setup\XenAppGpmx_x64.msi /qn

After the installation of the SDK you should import the Citrix.GroupPolicy.Commands.psm1 by using:

# Set execution Policy

Set-ExecutionPolicy Unrestricted -force

#Import Module

Import-Module “C:\xenapp 6.5\Citrix.GroupPolicy.Commands.psm1”

Based on the way you arranged your policies you can choose the way you backup your policies as stated in CTX128625

 

Exporting from IMA Datastore Farm Policy

Unless a PowerShell drive is specified, the Export-CtxGroupPolicy cmdlet defaults the the IMA Datastore Farm Policy. To export from the IMA Datastore run the command:

Export-CtxGroupPolicy <PathToExportFolder>

Importing to IMA Datastore Farm Policy

Unless a PowerShell drive is specified, the Import-CtxGroupPolicy cmdlet defaults the the IMA Datastore Farm Policy. To export from the IMA Datastore run the command:

Import-CtxGroupPolicy <PathToExportFolder>

Exporting from Local Server Policy

Unless a PowerShell drive is specified, the Export-CtxGroupPolicy cmdlet defaults the the IMA Datastore Farm Policy. To export from the local server policy run the command:

Export-CtxGroupPolicy –DriveName localgpo <PathToExportFolder>

Importing to Local Server Policy

Unless a PowerShell drive is specified, the Import-CtxGroupPolicy cmdlet defaults the the IMA Datastore Farm Policy. To import to the local server policy, run the command:

Import-CtxGroupPolicy <PathToExportFolder> –DriveName localgpo

Exporting from Active Directory GPO

  • 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 GPO being exported.
    New-PSDrive -Name <DomainGpoDrv> -PSProvider CitrixGroupPolicy –Root \ -DomainGpo <DomainGPO>
  • Export the GPO to a folder:
    Export-CtxGroupPolicy -DriveName <DomainGPODrv> <PathToExportFolder> 

Importing to Active Directory GPO

  • 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 GPO being exported. Note: The target GPO must already exist in the Active Directory domain.
    New-PSDrive -Name <DomainGpoDrv> -PSProvider CitrixGroupPolicy –Root \ -DomainGpo <DomainGPO>
  • Import the GPO from a folder:
    Import-CtxGroupPolicy <PathToExportFolder> -DriveName <DomainGPODrv>

In my case it would be the following script:

# Set execution Policy

Set-ExecutionPolicy Unrestricted -force

#Import Module

Import-Module “C:\xenapp 6.5\Citrix.GroupPolicy.Commands.psm1”

#Backup policy

Export-CtxGroupPolicy “C:\xenapp 6.5\backup”

You could store the backup (XML files) to a remote location if you want to. Andrew Morgan did some magic in Powershell to integrate this into one script and a blog will follow soon on his website, I will update this blogpost once it’s posted.
The following two tabs change content below.

Kees Baggerman

Kees Baggerman is a Staff Solutions Architect for End User Computing at Nutanix. Kees has driven numerous Microsoft and Citrix, and RES infrastructures functional/technical designs, migrations, implementations engagements over the years.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.