Did you ever want to fully automate your XenApp 6.5 farm? Did you manage an automated unattended installation or image, but you are struggling to automate farm configurations? Would you like to learn how to create worker groups for XenApp 6.5 with PowerShell? In this case, this article is just for you.
Automating Citrix consists of various components. You need to configure:
- Citrix administrators
- Citrix worker groups (explained in this article)
- Citrix user and computer policies
- Citrix load evaluators
Note: see the article PowerShell Fundamentals if you are new to PowerShell or if you just want to refresh your memory. Especially important is the part about loading snap-ins and modules. Remember, the appropriate extensions need to be loaded before Citrix commands can be executed! |
Creating worker groups using PowerShell
Worker groups only need to be created and not configured (except for adding servers of course). Only a single command line is needed to create a worker group (e.g. the worker group “Production”):
1 |
New-XAWorkerGroup -WorkerGroupName "Production" |
A worker group can contain:
- Active Directory containers (OUs)
- Active Directory server groups (security groups)
- Farm servers
The following command line adds the OU “Test” to the worker group “Production”:
1 |
Add-XAWorkerGroupServer "Production" -OUs "OU=Test,DC=abc,DC=com" |
To add a security group to the worker group “Production” use the following command line:
1 |
Add-XAWorkerGroupServer "Production" -ServerGroups "YourDomain\GroupName" |
The following command line adds the current farm server to the worker group “Production”:
1 |
Add-XAWorkerGroupServer "Production" $env:ComputerName |
In a fully automated environment it is my personal best-practice is to combine the creation of the worker group and adding an OU, security group or farm server in one script. I mean, why would you create the worker group and not any servers to it? You may as well do both things at the same time.
A professional (PowerShell) script needs more than a single line of code. In a professional script you need to:
- Add comments (e.g. script name, author, date and purpose of the script);
- Load the Citrix cmdlets;
- Check if the worker group exist;
- Create the worker group if it does not exist;
- Add the OU, security group or server to the worker group;
- Log actions and results.
Below follows an example of such as script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#========================================================================== # CREATE WORKER GROUP AND ADD SERVER # # AUTHOR: Dennis Span (https://dennisspan.com) # DATE : 20.11.2013 # Scripting language: PowerShell (v.2.0) # # COMMENT: This script creates a Citrix worker group and add the current server #========================================================================== # Logging: # "-" = comment # "I" = information # "S" = success (action successful) # "E" = error (action unsuccessful) # Set the error action preference to "stop" to ensure that the try and catch statements work for non-terminal errors $ErrorActionPreference = "Stop" # ================================================= # Configure variables $ComputerName = $env:ComputerName # Define the environment variable "ComputerName" $WorkerGroupName = "Production" # Define the name of the worker group this script should create # ================================================= # ================================================= # Load all Citrix cmdlets # ================================================= Add-PSSnapin citrix* # ================================================= # Task 1 of 2: Create worker group (if not exist) # ================================================= Write-Host ("I - Create the worker group $($WorkerGroupName.ToUpper()) (if not exists)") try { Get-XAWorkerGroup $WorkerGroupName | Out-Null Write-Host ("I - The worker group already exists") } catch { Write-Host ("I - The worker group does not exist") Write-Host ("I - Creating the worker group...") try { New-XAWorkerGroup -WorkerGroupName $WorkerGroupName.ToUpper() | Out-Null Write-Host ("S - The worker group $($WorkerGroupName.ToUpper()) has been created successfully") } catch { Write-Host ("E - Creating the worker group $($WorkerGroupName.ToUpper()) ended in an error") } } # ================================================= # Task 2 of 2: Add the current server to the new worker group # ================================================= Write-Host ("I - Add the current server $($ComputerName.ToUpper()) to the worker group $($WorkerGroupName.ToUpper())") try { Add-XAWorkerGroupServer $WorkerGroupName.ToUpper() $ComputerName.ToUpper() | Out-Null Write-Host ("S - The current server has been successfully added to the worker group") } catch { Write-Host ("E - Adding the current server to the worker group ended in an error") } |
Related articles:
- Automating XenApp 6.5 Part 1 of 4 – Citrix Administrators
- Automating XenApp 6.5 Part 3 of 4 – Citrix Policies
- Automating XenApp 6.5 Part 4 of 4 – Citrix Load Evaluators
- PowerShell “one-liners” for Citrix XenApp 6.x
Dennis Span works as a Lead Account Technology Strategist at Cloud Software Group in Vienna, Austria. He holds multiple Citrix certifications (CCE-V). Dennis has been a Citrix Technology Advocate (CTA) since 2017 (+ one year as Citrix Technology Professional, CTP). Besides his interest in virtualization technologies and blogging, he loves spending time with his family as well as snowboarding, playing basketball and rowing. He is fluent in Dutch, English, German and Slovak and speaks some Spanish.
Pingback: Automating XenApp 6.5 Part 1 of 4 - Citrix Administrators - Dennisspan.com