VB Script to Backup / Restore CPS policies - Guest Bloggers - BrianMadden.com
Brian Madden Logo
Your independent source for desktop virtualization, consumerization, and enterprise mobility management.
Guest Bloggers's Blog

Past Articles

VB Script to Backup / Restore CPS policies

Written on Dec 06 2007
Filed under: ,
29,687 views, 39 comments


by Mark Elliott

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.

 
 




Our Books


Comments

Stephen Pratt wrote You are the Man!
on Thu, Dec 6 2007 11:01 AM Link To This 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!
Chris De Jongh wrote wonderfull script
on Fri, Dec 7 2007 4:28 AM Link To This Comment

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

Cool.

hans straat wrote we all were waiting for this :)
on Fri, Dec 7 2007 7:28 AM Link To This Comment
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!
Beav wrote Policy Examples
on Fri, Dec 7 2007 9:00 PM Link To This Comment

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

Guest wrote Big Kev
on Sun, Dec 9 2007 9:43 PM Link To This Comment
Mark, You're the man!!!
Brian Thornton wrote 100 policies or more to migrate to new Farm....
on Mon, Dec 10 2007 5:38 AM Link To This Comment

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 - http://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?

 Brian

Guest wrote Check printer connection
on Wed, Dec 19 2007 12:54 PM Link To This Comment

HI

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

 

conrad.walker@capitalone.com wrote Great Script
on Thu, Dec 20 2007 10:24 AM Link To This Comment
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
Guest wrote Important Question
on Mon, Dec 31 2007 2:34 AM Link To This Comment

First, thanks a lot fot the scripts.

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

TNX,

Uri

Mark Elliott wrote Re: Important Question
on Mon, Dec 31 2007 4:29 PM Link To This Comment
Yes. That should be possible. I didn't test extensively but I can't think of any reason it wouldn't work
Guest wrote error
on Tue, Feb 12 2008 12:00 PM Link To This Comment

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?

Guest wrote Great idea ! - but issue with Session Printer policies in PS4.0
on Mon, Feb 25 2008 11:04 AM Link To This Comment

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.

 Cheers

 Dave K.

Guest wrote Re: error
on Mon, Mar 3 2008 2:03 PM Link To This Comment
I'm getting the same error, did you ever get it resolved?
Jose Manuel Carballo wrote Uuuups not working.
on Tue, Mar 11 2008 12:10 PM Link To This Comment

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
icy.UserPolicy.EnableSSPDLossyCompThreshold'

 

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

Regards.

 

Guest wrote Re: error
on Tue, Mar 25 2008 2:05 PM Link To This Comment
I had the same problem.  Needed to have at least R03 on my PS4.0 server farm.
Guest wrote Failed to add all printers in PRINTERCONNECTIONS
on Wed, Apr 9 2008 5:27 AM Link To This Comment
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
Guest wrote With Backup and restore only Policy names
on Mon, Apr 21 2008 8:50 AM Link To This Comment

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

Trevor Worrall wrote Backup Policies from 4.0 restore to 4.5
on Mon, Apr 21 2008 1:36 PM Link To This Comment

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.

 

Cheers 

 

 

Guest wrote Backup Policies from 4.0 restore to 4.5
on Tue, Apr 22 2008 4:31 PM Link To This Comment

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

 

Regards

Trevor

Guest wrote Backup Policies from 4.0 restore to 4.5
on Tue, Apr 22 2008 4:51 PM Link To This Comment

OK Dirty fix.

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

Coment out lines :--

234-239

251-253

418-422

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

 

Regards

Trevor 

 

 

 

Guest wrote Re: Failed to add all printers in PRINTERCONNECTIONS
on Mon, May 5 2008 1:50 PM Link To This Comment
I'm having the same issue.  Were you able to resolve this issue with the script?
Mark Elliott wrote Updated Scripts
on Thu, May 15 2008 10:22 AM Link To This Comment

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

Guest wrote Error
on Wed, Jun 18 2008 9:11 PM Link To This Comment

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?

Guest wrote Dave
on Tue, Jul 8 2008 6:22 AM Link To This Comment

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 />   

Ryan Campbell wrote Null error on line 427
on Thu, Jul 10 2008 12:56 PM Link To This Comment

<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. 

lox wrote best practise ?
on Thu, Jul 17 2008 6:43 AM Link To This Comment

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!

lox wrote solved
on Thu, Jul 24 2008 6:54 AM Link To This Comment

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

Guest wrote Re: Failed to add all printers in PRINTERCONNECTIONS
on Fri, Jul 25 2008 12:57 AM Link To This Comment

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

lox wrote importing/restoring particular xml-files
on Mon, Aug 11 2008 7:14 AM Link To This Comment

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 ?

Markus Korhonen wrote re: VB Script to Backup / Restore CPS policies

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?

Guest wrote Failing to Restore, please help!
on Mon, Sep 15 2008 9:16 AM Link To This Comment

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 

Guest wrote Re: Failed to add all printers in PRINTERCONNECTIONS
on Tue, Sep 16 2008 4:48 AM Link To This Comment

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

Guest wrote Restore on 4.5 from 4.0
on Thu, Oct 2 2008 7:28 PM Link To This Comment

<!--[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 />

Guest wrote Re: Restore on 4.5 from 4.0
on Fri, Oct 3 2008 5:51 AM Link To This Comment

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!  

Guest wrote Re: Uuuups not working.
on Wed, Oct 8 2008 4:18 AM Link To This Comment

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

Is there a workaround ?

Guillermo Musumeci wrote re: VB Script to Backup / Restore CPS policies
on Tue, Dec 23 2008 8:12 AM Link To This Comment

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

CCA, CCEA, MCSE, MCSD, MCDBA, MCITP, VCP

Tord Bergset wrote re: VB Script to Backup / Restore CPS policies
on Tue, Jan 20 2009 7:42 AM Link To This Comment

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

Pierre Marmignon wrote re: VB Script to Backup / Restore CPS policies
on Tue, Jul 14 2009 12:58 PM Link To This Comment

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,

Pierre

(Note: You must be logged in to post a comment.)

If you log in and nothing happens, delete your cookies from BrianMadden.com and try again. Sorry about that, but we had to make a one-time change to the cookie path when we migrated web servers.

Trackbacks

Cps policys | Ajaygoud wrote Cps policys | Ajaygoud
on Mon, Jun 27 2011 4:56 PM

Pingback from  Cps policys | Ajaygoud