Modify Citrix Policy With Powershell

I had to recreate an 4 day scheduled reboot plan on an XA65 farm, so i look for a way to recreate all these policies with powershell. When we load Citrix snapins, we automatically create 3 PSDrive, using CitrixGroupPolicy provider, these drives are accessible with a set-location.

PS C:\> get-psdrive -PSProvider CitrixGroupPolicy

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
LocalFa...                             CitrixGrou... LocalFarmGpo:\
LocalGpo                               CitrixGrou... LocalGpo:\
Templates                              CitrixGrou... Templates:\

Under the “Computer” tree, we find all the computer policies, with some interesting properties like Name, Description, Enabled, Priority (…).

PS LocalFarmGpo:\> ls computer | select name
Name
----
Default-conf
Reboot-monday
Unfiltered

PS LocalFarmGpo:\computer> get-itemproperty reboot-monday


Name         : Reboot-Monday
Description  : Policy Reboot on Mondau
Enabled      : True
Priority     : 5
PSPath       : Citrix.Common.GroupPolicy\CitrixGroupPolicy::LocalFarmGpo:\Computer\Reboot-Monday
PSParentPath : Citrix.Common.GroupPolicy\CitrixGroupPolicy::LocalFarmGpo:\Computer
PSChildName  : Reboot-Monday
PSDrive      : LocalFarmGpo
PSProvider   : Citrix.Common.GroupPolicy\CitrixGroupPolicy

If i want to set up a policy at the top priority, instead of multi-clicking to raise the priority of my policy, i can simply set it up with “set-itemproperty”.

set-itemproperty MyPolicy –name priority –value 1

The parameters are under the “settings” tree, if i want to get the value of “LoadEvaluator” in the LE-EVALUATOR policy :

PS > get-itemproperty LocalfarmGPO:/Computer/LE-Evaluator/Settings/ServerSettings/Loadevaluator

State        : Enabled
Value        : LE-Evaluator
PSPath       : Citrix.Common.GroupPolicy\CitrixGroupPolicy::LocalFarmGpo:\Computer\LE-Evaluator\Settings\ServerSettings\LoadEvaluator
PSParentPath : Citrix.Common.GroupPolicy\CitrixGroupPolicy::LocalFarmGpo:\Computer\LE-Evaluator\Settings\ServerSettings
PSChildName  : LoadEvaluator
PSDrive      : LocalFarmGpo
PSProvider   : Citrix.Common.GroupPolicy\CitrixGroupPolicy

In the same way that with the priority setting, i can set up the loadevaluator value with set-itemproperty

set-itemproperty  LocalfarmGPO:/Computer/LE-Evaluator/Settings/ServerSettings -Name LoadEvaluator -Value "LE-EVALUATOR"

Here an example, Creation of scheduled reboot plan, we copy the first policy and then we modify the duplicated policies to fit our needs :

If( -not (get-psdrive –name localfarmgpo)){ New-PSDrive -Name LocalFarmGpo -PSProvider CitrixGroupPolicy -Root \ -FarmGpo localhost }
Cd localfarmgpo:\Computer
Cp reboot-monday reboot-tuesday
Cp reboot-monday reboot-wednesday
Cp reboot-monday reboot-thursday
$priority = (get-itemproperty localfarmgpo:/computer/reboot-monday).priority
set-itemproperty reboot-tuesday–name priority –value ($priority + 1)
set-itemproperty reboot-wednesday–name priority –value ($priority + 2)
set-itemproperty reboot-thursday–name priority –value ($priority + 3)

cd LocalFarmGpo:\Computer\Reboot-Mardi\Settings\ServerSettings\rebootBehavior
set-itemproperty RebootScheduleStartDate -Name startdate -value "$(get-date (get-date).AddDays(2 - (get-date -UFormat %u)) -UFormat "%D 00:00:00")" 
cd LocalFarmGpo:\Computer\Reboot-Mardi\Settings\ServerSettings\rebootBehavior
set-itemproperty RebootScheduleStartDate -Name startdate -value "$(get-date (get-date).AddDays(3 - (get-date -UFormat %u)) -UFormat "%D 00:00:00")"
cd LocalFarmGpo:\Computer\Reboot-Mardi\Settings\ServerSettings\rebootBehavior
set-itemproperty RebootScheduleStartDate -Name startdate -value "$(get-date (get-date).AddDays(4 - (get-date -UFormat %u)) -UFormat "%D 00:00:00")"

Leave a Reply

Your email address will not be published. Required fields are marked *