The Citrix Cloud Connector is a critical component of all Citrix XenApp & XenDesktop Cloud deployments. It’s the glue that connects your local resources (hypervisors, VDAs, Storefront servers, and so on) to Citrix Cloud and is required by the service.

At its most basic level, the Cloud Connector is simply a domain-joined Windows 2012 R2 or Windows 2016 server that is able to communicate with the resources in the Resource Location that you want to manage from your Citrix Cloud Library. The Connector then provides a secure channel for communication between Citrix Cloud and your Resource Locations to facilitate Active Directory, XenApp/XenDesktop Publishing and Delivery group provisioning.

If you have an existing Citrix Cloud environment, chances are you already breezed through the Connector setup. Due to its hassle-free design and outbound-only communication, there is no need for any special configuration (i.e. firewalls, NAT/proxy considerations, etc.); just install the recommended two connectors per resource location and you’re up and running.

If you haven’t yet deployed your Citrix Cloud Connectors (or find yourself doing it repeatedly or simply want to integrate it into an existing deployment solution) consider automating it for a completely unattended process!

Getting Started

Before we begin, we need a few things:

  1. Resource Location: Citrix Cloud connects to your local resources in resource locations you define. We need an existing resource location that this Connector will provide access to. For more details on resources locations, including what they provide and where they should be located see: http://docs.citrix.com/en-us/citrix-cloud/overview/about/what-are-resource-locations.html

Note: For completely fresh deployments where no resource zones exist, it’s possible to automated the resource zone creation as well using the POST method of the same endpoint used for enumerating resource locations below.

  1. Secure Client: A secure client consists of a Client Id and Client Secret and is required to interact with Citrix Cloud APIs. It can be created on the API Access page under Identity and Access Management in Citrix Cloud as shown below.

secureclient

The Automation

Now let’s layout the core steps required for the automation and delve a bit deeper into each:

  1. Download the latest Citrix Cloud Connector installation package
  2. Get the Id of the ResourceLocation where we want to install the Connector
  3. Run the installation

Download the latest Citrix Cloud Connector installation package: Using the same installer for repeated installations over a period of time is not recommended. Therefore your automation should always download the latest version as shown in the below code snippet:

$downloadsUri = 'https://downloads.cloud.com/$customerId/connector/cwcconnector.exe'
Invoke-WebRequest -Uri $downloadsUri -OutFile $pwd

Get the Id of the Resource Location where we want to install the Connector: The connector installation msi requires a ResourceLocationId to associate the connector with a resource location. We can obtain this Id using the Citrix.CloudServices.Registry.Api endpoint ‘GET {customer}/resourcelocations’. It’s important to note that this API requires an Authorization header we must first generate using our Secure Client and the Citrix.CloudServices.Trust.Api as shown in the below code snippet:
$Body = @{
clientId = $ClientId
clientSecret = $ClientSecret
}
$TrustResponse = Invoke-RestMethod -Uri $trustUri -Method "Post" -Body (ConvertTo-Json $Body) -ContentType application/json -Verbose
$cwcBearerAuthHeaderValue = "CWSAuth bearer=`"$($TrustResponse.token)`""
$cwcAuthHeader = @{"Authorization" = $cwcBearerAuthHeaderValue}
$registryServiceUri = "https://registry.citrixworkspacesapi.net/$customerId/resourcelocations"
$registryResponse = Invoke-RestMethod -Method GET -Uri $registryServiceUri -Headers $cwcAuthHeader -ContentType "application/json" -Verbose
Write-Host "Customer Resource Location Id $($registryResponse.items.id)"

     Note: This endpoint will return all resource locations that exist for your customer.
     Note: You can manually confirm the Id by pressing the ID button for the Resource Location in the Citrix Cloud site as shown below.
resourcelocation
Run the installation: The official documentation for the connector installation can be found here and includes silent installation flags we will use.

$args = "/q /CustomerName:$CustomerId /ClientId:$APIClientID /ClientSecret:$APIClientSecret /Location:$customerResourceLocationsId /AcceptTermsOfService:true"
Start-Process .\cwcconnector.exe $args -Wait

Depending on your needs you can include even more sophisticated deployments scripts to support your specific requirements. For example, you may wish to utilize the Citrix.CloudServices.AgentHub.Api to check for and remove existing connectors in your resource location before deploying new ones.
Use the following link to download a complete example script to get you started.

.\DeployCitrixCloudConnector.ps1 -CustomerId {YourCustomerName} -APIClientID {YourClientID}' -APIClientSecret {YourClientSecret} -ResourceLocation {NameOfResourceLocationToUse}

blog-banners-footer-8