This article contains examples of PowerShell script designed to launch XenApp commands and being able to perform data manipulation between commands in one script.
Microsoft Windows Server 2008 R2
Citrix XenApp 6.0 or 6.5
Microsoft PowerShell
In some cases administrators have the need to capture information from PowerShell and also manipulate it for other wrong commands. Many PowerShell commands can be combined together using pipes. For example: Get-XAApplication | Clear-XAApplicationLoadEvaluator
This command removes the load evaluator from each one of the applications.
In this one line command example, the administrator has no opportunity to see the data captured by the Get-XAApplication before it is used under the Clear-XAApplicationLoadEvaluator, this article contains examples of other ways to launch this command so there is space in between for some data manipulation or data reporting.
Following are two examples to understand PowerShell script designed to launch XenApp commands:
Usage
The following PowerShell command reports each application name and removes its load evaluator.
Write-Host "Adding Citrix Powershell Snapin..." Add-PSSnapin Citrix.XenApp.Commands Write-Host "Checking applicatoon list and removing load evaluators." ForEach ($App in Get-XAApplication) { Clear-XAApplicationLoadEvaluator -BrowserName $App.BrowserName } Write-Host "Job Done, Have a Nice Day !!"
This script works the same as the preceding one line command. The data between the steps can be worked on in this approach. This method provides flexibility to report or validate with certain condition.
Usage
The following PowerShell command reports each application name, removes its load evaluator, except on applications from the Microsoft Office Suite.
Write-Host "Adding Citrix Powershell Snapin..." Add-PSSnapin Citrix.XenApp.Commands $y = 0 Write-Host "Checking applicatoon list and removing load evaluators." ForEach ($App in Get-XAApplication) { if($App.DisplayName-notlike "*Microsoft*") { Clear-XAApplicationLoadEvaluator -BrowserName $App.BrowserName } else { $y += 1 } } Write-Host "The load evaluator was not removed from $z application(s)." Write-Host "Job Done, Have a Nice Day !!"
Adding extra steps to the script can verify each application name and validate if it contains the word Microsoft, if it exists load evaluator is not removed, if it does not exist the load evaluator for the application is cleared.
In certain areas of the script, code is added to write messages to the console, this is useful for farms that have a lot of applications. Using this message an administrator gets an idea that the script is running and the progress so far. Also this script contains a count result to report how many applications were not modified in total.
This article implies that the XenApp PowerShell commands are quite flexible, similar to the native commands existing in Windows PowerShell. Many tasks can be completed using the same logic. This can be used for monitoring, reporting, configurations, and so on. The one line commands as mentioned at the beginning of the article can be used, but to have all or most of your routines simplified or even automated this is a good approach. This helps reducing resources in routine and replacing it with higher priority tasks.
Citrix Download - Citrix XenApp 6.0 SDK
Citrix Download - Citrix XenApp 6.5 SDKCTX126471 - How to Install and Enable XenApp 6.0 SDK
CTX126287 - How to Use Microsoft PowerShell with Configuration Logging to Export DataCTX126987 - How to Capture a CDF Trace with PowerShell in XenApp 6