VB Script to Backup / Restore CPS policies

In response to several requests in our forums, Mark Elliott has written a couple of VB scripts that backup and restore policies stored in a Citrix Presentation Server 4.0 or 4.

In response to several requests in our forums, Mark Elliott has written a couple of VB scripts that backup and restore policies stored in a Citrix Presentation Server 4.0 or 4.5 farm.

The backup script is pretty straightforward. It allows you to parse two (optional) parameters:

  • Logging detail level
  • XML file name the policy information is written to

The restore script has some more parameters, all of which are optional. For example, you can:

  • Specify the logging detail
  • Whether or not to apply the policy filter
  • Whether or not to overwrite a policy if it already exists
  • The name of the XML file that you're restoring (from the backup script)
  • The policy name (if you only want to restore a subset of the policies in the XML file)

Download a ZIP file containing these two scripts here.

Join the conversation


Send me notifications when other members comment.

Please create a username to comment.

Thank You! Thank You! Thank You!  I am about to migrate 3 different farms into one and all 3 of them have a ton of policies.  I was wondering how I was going to automate this because there was no way I was going to do it manualy.  Thank You!

I was just writing a script my own to accomplish the same.


We all were waiting for someone writing a script to backup or restore polices. Thank you mark for writing it but more for sharing it with the community!

Is there a good comprehensive list of policies and how people design them? 

Mark, You're the man!!!

Excellent will be this is a life saver for us....

For my own interest(question for all those who read this article) how many policies do people have implemented in their environments?

We have 168 mostly printer mapping policies. This is contrary to what CITRIX advise (too many policies will slow down logon process, not something we have experienced I might add) but goes against Brian's claims in this article - https://www.brianmadden.com/content/article/Best-Practices-for-Citrix-Policy-design-for-Presentation-Server-3-or-4

....Yeah, that’s right. You may have 100 or more Citrix policies in your farm.

Before we look at how you should create policies, I want to shoot down a myth about the number of policies you can create in a farm. I’m not sure if this is from some deeply-buried KB article or some news group myth or what, but there’s some kind of industry-wide fear of creating too many policy objects. Most people balk at the idea of 100 policies in a Citrix farm. “That’s too many!” they say, or, “That will make logons too slow.”

“Nonsense!” is my response. I think you need to make as many policies as you need to get the job done, and if that means that you end up with 100 policy objects in one farm, then so be it.......

So how many policies have you implemented in your FARMs?




The script is very useful , my situation is very particular.

My problem is to test if exist a session printer policy  without printer connections, I build a script from this script, but I'm not a programmer and I'm not able to test this condition. Before line 231 of BackupPolicy.vbs I want to test if exist any printer connection for the policy.

  Many thanks




  What I 've to test


Thanks for this Mark really comes in handy for me as we have 579 print policies, as each shop has a seperate printer policy assigning a session printer for there store. Just a note we have no slowdown on logon as there is only two policies assigned to each global group logon

First, thanks a lot fot the scripts.

Can I backup the policies from 4.0 farm and restore them to 4.5 farm?



Yes. That should be possible. I didn't test extensively but I can't think of any reason it wouldn't work

im trying to run this in a PS4 farm and i get an error (233, 8) (null)


it worked fine in my test farm. Not sure why it wont in my production farm.


It is probably something simple. Any ideas?


Hey all,

     Trying to use the script to simply migration to PS 4.5 and when attempting to backup the existing PS4.0 Session Printer policies receiving the following error message - "Object doesnt support this property or method: aSessionPrinter.UseCustomSettings". I have the line number somewhere will dig it out for you. Any help greatly appreciated.


 Dave K.

I'm getting the same error, did you ever get it resolved?

Hi all,

Trying to launch a Backup in a PS4 Rollup 2 server is giving this error: 

(I) Connecting to Citrix farm
(I) Setting XML File
(I) Processing policy: Todos
(I) Processing Bandwidth\Visual Effects policies in Todos
(I) Processing Bandwidth\Speedscreen policies in Todos
D:\Software\Backup Policies\CitrixPolicyBackup\BackupPolicy.vbs(167, 13) Microso
ft VBScript runtime error: Object doesn't support this property or method: 'aPol


It seems like I need to upgrade or apply any Citrix Patch. Does anybody know?



I had the same problem.  Needed to have at least R03 on my PS4.0 server farm.
We are running the restore and it is not adding all the printers back in to the PRINTERCONNECTIONS. Only adding the last printer in the list. Any ideas

Hello, I seem to be having trouble with this script and I am not sure why. I am trying to copy this from production into a test upgrade environment. The backup seems to work ok and the restore does not error out. When I open the policy that was restored there seem like blank policies with just the name carried over. Any help is appreciated


When I found this I thought the moving of the policies is now going to be a breeeze. The Backup worked atreat and the XML file was created. Quick look through and yep looked good. Copy over to 4.5 new farm type in the restore command and bang out with an error : restorepolicy.vbs(235,14) runtime erroe: opbject required 'objNode.getElementsbyTagName(...).item(...)

It creates the policy name, enables it but does not populate the policy

Any suggestions before I resort to the tried and tested way, manual entry.






It seams to revolve round the differences in policy content , the first bit is on speed screen. Around Speed screen progressive display compresion.





OK Dirty fix.

There is a difference between 4.0 & 4.5 policies, no surprise there.

Coment out lines :--




the script appears to work, adds connections and all detail. Script really needs modifying to check the difference or even in the backup write a tag for PS version :)


Hope this helps guy's







I'm having the same issue.  Were you able to resolve this issue with the script?

I've modified the scripts now so the backup script records in the XML file the version of PS the backup was run from. When the restore script runs, it shouldn't try and apply any 4.5 only settings as these settings won't exist in the XML file.

It still needs a lot more error checking in it but hopefully it will get some people out of trouble. Also, as a poster mentioned earlier, it needs PS4.0 R03 or higher.

I'll contact Brian to get the modified scripts updated on the site


Mark,I am getting the following error when trying to restore from a successful Backup XML file:C:\Temp>cscript RestorePolicy.vbs -file:COA-CTXProd-Policies.xml -pf:0 -po:1<br />Microsoft (R) Windows Script Host Version 5.6<br />Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.C:\Temp\RestorePolicy.vbs(130, 9) Microsoft VBScript runtime error: This key is<br />already associated with an element of this collection Any ideas what this could be?


Using it on a 4..5 farm - I copied both scripts to C:\TempBackup worked fine and created the XML fileBut what is the syntax for a default restore - I've tried this but nothing happens - no errorscscript RestorePolicy.vbs -file:2008CTX-Policies.xml<br />   


<em>C:\TEMP>cscript backuppolicy.vbs -lo:3<br />Microsoft (R) Windows Script Host Version 5.6<br />Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.<br /><br />(I) Connecting to Citrix farm<br />(I) Setting XML File<br />(I) Processing policy: Domain Users<br />(I) Processing Bandwidth\Visual Effects policies in Domain Users<br />(I) Processing Bandwidth\Speedscreen policies in Domain Users<br />(I) Processing Bandwidth\Session Limits policy in Domain Users<br />(I) Processing Client Devices policies in Domain Users<br />(I) Processing Printing policies in Domain Users<br />(I) Processing User Workspace policies in Domain Users<br />(I) Processing Shadowing polices in Domain Users<br />(I) Processing User Workspace\Time Zone settings in Domain Users<br />(I) Processing User Workspace\Password Manager settings in Domain Users<br />(I) Processing Security settings in Domain Users<br />(I) Processing Virtual Channel settings in Domain Users<br />(I) Processing Policy Filter settings in Domain Users<br />(I) Processing Access Control filter for Domain Users<br />(I) Processing Client IP filter for Domain Users<br />(I) Processing Client Name filter for Domain Users<br />(I) Processing Server filter for Domain Users<br />(I) Processing User filter for Domain Users<br />C:\TEMP\backuppolicy.vbs(427, 7) (null): Unspecified error</em> Line 427 is...            For Each aAccount in aPolicy.PolicyFilter.AllowedAccounts Anyone?  This is XenApp 4.5 R02 farm. 


hi,i am really happy with that script, but i ran into some questions.i created a script that generates me around 700 printer-policies to import them on a new farm.i considered to make one big xml-file, though the handling with seperate xml-files is way better - especially when adding additional printers in the future.now, when i run the for-loop to import those policies (xml-files) i get a authentication-popup for each "printer", that means again 700 interactions :Sso here the questions:is it possible to suppress that checkback or to provide the password in the script ?while creating the xml-file i thought about making a growing counter that defines me the value "<priority>1....700</priority>" till i found out that the policy-priority will be set with the next higher value automatically even using the same value like "1" for example.so should i leave value "1" for all 700 policies since it works ? ro is there any "wildcard" to make it the proper way ? thx in advance!


ok, i solved it.made a ascript that creates one big xml-import-file that includes all printers and fix policies and besides that 700 single xml-import-files so i is still modular to import/remove/change printers later


Got the same problem here...only restoring the last printer in the list...help anyone... please...


now that i got one major xml-file that i could restore if my datastore ever get corrupted, i got furthermore 700 single xml-files (1 per printer).<br />when we get a new printer (ic printer No. 701) in the farm, the xml-file printer_bla_701.xml is created automatically and the major xml-file is properly updated.<br />now when i try to restore/import the "printer_bla_701.xml", it seems whole set of already included policies in the datastore is checked again, since it takes about 10-15 minutes till the new printer is imported.is there any way to speed this up ?


Hope someone can help me with this ;-)

The farm is the same as the one backuped from so the are no differences in version or other.

The BIG change is that the print server where all the session printers are connected was changed from servernameA to ServernameB.

I backed upp the policies.

Did a Search and replace of the server name in the XML file so that it reflects the new server name.

Now I need to do the restore with the newly edited XML file.

This is what comes out!

C:\drift\temp\RestorePolicy.vbs(83, 21) Microsoft VBScript runtime error: Subscript out of range: '[number: 1]'

Any Suggestions?


This is what i want do do.I have a PS4.5 farm with a lot of Session printers configured.The printserver is being changed so now i need to do a lot of changing on Session Printers.The backup goes well, I search and raplace the servername in the XML, then i try to Restore.The first few policys goes smooth and then there is a Authentication message just when the printepolicys are being processed. >> A policy to be restored contains session printers which requires AD authentication. <br />>> Please enter password for domain<strong>\username</strong> I anter the correct password but the script gives me.>> RestorePolicy.vbs(298, 16) Microsoft VBScript runtime error : Invalid procedure call or argumentAny ideas on this or is it manual management!? ;-) Best regardsMarkus K 


Same problem here!!Someone who solved this and how?  


<!--[if gte mso 9]><xml>  <w:WordDocument>   <w:View>Normal</w:View>   <w:Zoom>0</w:Zoom>   <w:PunctuationKerning/>   <w:ValidateAgainstSchemas/>   <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>   <w:IgnoreMixedContent>false</w:IgnoreMixedContent>   <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>   <w:Compatibility>    <w:BreakWrappedTables/>    <w:SnapToGridInCell/>    <w:WrapTextWithPunct/>    <w:UseAsianBreakRules/>    <w:DontGrowAutofit/>   </w:Compatibility>   <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>  </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml>  <w:LatentStyles DefLockedState="false" LatentStyleCount="156">  </w:LatentStyles> </xml><![endif]--> <!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> <!--[if gte mso 10]> <style>  /* Style Definitions */  table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->  I'm having trouble with the restore from a 4.0 R05 farm to 4.5 R02 target farm. If anyone has any pointers I would be very appreciative.      Thanks in advance!   cscript Restorepolicy.vbs -lo:3 -pf:1 -po:1 -policies:"Default User Policy"<br />Microsoft (R) Windows Script Host Version 5.6<br />Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.<br /><br />(I) Connecting to Citrix farm<br />(I) Adding Default User Policy to Policy Dictionary object<br />(I) Adding Bertha to Servers Dictionary object<br />(I) Loading XML File<br />(I) Entering Restore<br />(I) Processing policy: Default User Policy<br />(W) Policy Default User Policy exists. Policy overwrite set to true. Overwriting.<br />(I) Creating Policy Default User Policy<br />(I) Processing Visual Effects policies for Default User Policy<br />(I) Processing SpeedScreen policies for Default User Policy<br />D:\Restorepolicy.vbs(235, 14) Microsoft VBScript runtime error: Object required: 'objNode.getElementsByTagName(...).item(...)'<br />


I guess the script changes were never updated on the site. As someone mentioned above commenting out the following lines worked. Coment out lines :--234-239251-253418-422Thanks for sharing Mark!  


I have the same error ! (PS4.0 R05)

Is there a workaround ?


I wrote a tool to backup/restore or import/export policies between farms (I need to move 464 policies from 4.0 farm to 4.5 farm).

I tried to run the backup script created by Mark on my 4.0 farm and fails, I review the code and made a couple of changes and still fails... so I check my code and found some code to export session printers I wrote in June 2008, I took some pieces of code from Mark scripts (I loved the XML file option...my old code used a TXT file) and review MFCOM guide and got more code from there.

The free tool is available at ctxadmtools.musumeci.com.ar

Ctx Policies Manager backup/restore/migrate Citrix Presentation Server 4.0 and Citrix XenApp 4.5 farms. I backup policies in both Citrix Presentation Server 4.0 and Citrix XenApp 4.5 farms and restore successfully in the Citrix XenApp 5.0 farm. Backup/Restore/Migration between Citrix XenApp 5.0 farms is not fully supported in this version.

Guillermo Musumeci

Windows Infrastructure Architect



Guillermo - thanks for the tip. Your tool(s) work fine for me :-)


Dear All,

Inspired by Mark's script I've also wrote a tool to manage Policies Export / Import.

My tool has been designed to be compatible with the XML files built by Mark's Scripts.

I've only added a tag to know from wich XenApp Version the Export was run.

XenApp Policies Export Manager has two components : A GUI and a Command Line version in case you want to run it programmatically.

You can also select the policies you want to backup / restore and if you want to apply filters or even disable the policy just after import.

XenApp Policies Export Manager is available on my site : http://www.citrixtools.net

It has been designed to run on XenApp 4.0, 4.5 and 5.0 although new XenApp 5.0 policies are not integrated in the initial release.

Best Regards,