Function – Get the servers from a Citrix Workergroup

Citrix, Powershell

Function – Get the servers from a Citrix Workergroup

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
function GetWorkerGroupServers {
	param (
		[Parameter()]
		[string]$workerGroupName = "ALL"
	)
 
        #add the Xen App Commands powershell Snapin
 
	if (-not(Get-PSSnapin "Citrix.Xenapp.Commands" -ErrorAction Silentlycontinue)) {
		try {
		        Add-PSSnapin "Citrix.Xenapp.Commands" -ErrorAction Stop 
		} catch {
			Write-Warning "The Citrix Xen App Commands snapin failed to install. Check that this server has the snapin installed and try again. `nError Message: $_"
		}
	}			
 
	try {
		if ($workerGroupName -eq "ALL") {
			return $workerGroupServers = get-xaserver -errorAction Stop | sort-object -property ServerName #get all citrix servers in the environment, in alphabetical order
		} else {
			return $workerGroupServers = get-xaworkergroupserver -workergroupname $workergroupname -errorAction Stop | sort-object -property ServerName #get all citrix servers in the specified workergroup, in alphabetical order
		}
	} catch {
		Write-Warning "Retrieving the servers in the Worker Group $workerGroupName failed. `nError Message: $_"
	}
}

Leave a Reply

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