Jo Harder posted a great blog yesterday explaining the changes in XenApp 6 management. One recommendation she made – and I agree – was to use Group Policies instead of Farm policies to manage your environments. The main benefit is that these policies will apply to more than one farm, for example, your development and test environments.

Well, that’s great, but the XA6 migration tool moves XA5 session policies, farm and server settings to Farm policies… We’ve done it this way to avoid requiring a Group Policy (and delegation to) during the migration process.

She asked me, how can one transfer these policies to a GPO, if they want to migrate and follow best-practices. Well, after some tinkering, here’s the script. Run this at any server in the XA6 farm.

By the way: if you want to copy settings from one GPO to another, you can use the export/import feature from the GPMC GUI itself. If you have XA6 console installed alongside that GPMC, Citrix settings will be correctly transferred. You just need the script to move settings to and from the IMA Farm Policy.

NOTE: Remember to replace the server and GPO name in the New-PSDrive lines!

Add-PSSnapIn Citrix.Common.GroupPolicy -ErrorAction SilentlyContinue

function MoveCitrixPolicies ($sourcePath, $targetPath)
  # Save priority lists - these are not preserved on transfer
  $CP = Get-ChildItem $sourcePath\Computer | Select Name, Priority | Sort Priority
  $UP = Get-ChildItem $sourcePath\User | Select Name, Priority | Sort Priority

  # Move all policies
  Get-Item $sourcePath\Computer\* -Exclude <span class="code-quote">"Unfiltered"</span> | ForEach { Move-Item $_.PSPath $targetPath\Computer }
  Get-Item $sourcePath\User\* -Exclude <span class="code-quote">"Unfiltered"</span> | ForEach { Move-Item $_.PSPath $targetPath\User }
  Copy-Item $sourcePath\Computer\Unfiltered $targetPath\Computer\Unfiltered
  Copy-Item $sourcePath\User\Unfiltered $targetPath\User\Unfiltered
  Clear-Item $sourcePath\Computer\Unfiltered
  Clear-Item $sourcePath\User\Unfiltered

  # Fix priorities
  foreach ( $p in $CP)
    Set-ItemProperty -LiteralPath $targetPath\Computer\$($p.Name) -Name Priority -Value $p.Priority

  foreach ( $p in $UP)
    Set-ItemProperty -LiteralPath $targetPath\User\$($p.Name) -Name Priority -Value $p.Priority

# Mount POlicies
New-PSDrive -PSProvider CitrixGroupPolicy -Name SourceGPO -Root \ -FarmGpo <span class="code-quote">"&lt;any IMA servername&gt;"</span>
New-PSDrive -PSProvider CitrixGroupPOlicy -Name TargetGPO -Root \ -DomainGpo <span class="code-quote">"&lt;any AD GPO name&gt;"</span>

MoveCitrixPolicies <span class="code-quote">"SourceGPO:"</span> <span class="code-quote">"TargetGPO:"</span>
Remove-PSDrive SourceGPO
Remove-PSDrive TargetGPO