Thursday, June 11, 2020

Stupid Citrix Trick #1: Dynamically Configuring Which Controllers a Citrix Server Connects To

Problem: The Citrix team where I work was tasked with setting up a large number of sites, connected by WAN links. Initially we tried using a single hub and zones, but in the current version of XenDesktop at the time (7.9), performance of Studio with remote sites over slow links was very poor, unusably so.

We needed a way to configure the VDAs at each site to connect to the local controllers. The session hosts were all running Provisioning Services images, and we didn't want to have to edit the image at each site to use the correct controllers.

Solution: The best solution would have been to use Group Policies to specify the controllers we wanted, but this was not practical 1) the computer accounts were all kept in a single AD container, and 2) the administrative overhead in creating GPOs meant that they would not have been ready anyway. So I turned the expert I trust most - Dr. Google.

I found that there is a way to configure the Citrix VDA from the command line, though it's not well documented. So I created a small batch file, stuck it on the session hosts' persistent drive, and created a scheduled task in the server image to run it at startup (actually startup + 2 minutes). Here it is. (It's difficult to read, but the list of controllers is space-delimited):

REM Set the list of controllers.
SET Controllers="controller1.siteA.company.com controller2.siteA.company.com"

REM Configure the Citrix Virtual Delivery Agent.
Start "Configuring Citrix VDA" /wait "%ProgramFiles%\Citrix\Virtual Desktop Agent\Agent Configuration\AgentConfig.exe" /ExecutionMode:Reconfigure /Controllers:%Controllers% /Enable_Firewall_Port:true /PortNumber:80 /Log:"C:\Temp\agent.log"

REM Restart Citrix Virtual Desktop Service.
Start "Stopping Citrix VDA Service" /wait net stop BrokerAgent
Start "Starting Citrix VDA Service" /wait net start BrokerAgent

Presto! All we had to do then was make sure the each server had the batch file with the list of controllers that corresponded to its site.