To easily be able to use PowerShell to administer XenApp 6, first you need to download and install the SDK. And I like to have my admin tools as published apps, so this is how to create a XenApp 6 PowerShell based management application as a hosted application on your farm:
Publishing the PowerShell console with XenApp commands
- Download the XenApp Powershell SDK : http://community.citrix.com/display/xa/XenApp+6+PowerShell+SDK
- Extract and execute the installer
- Agree to change the execution level to AllSigned
- Publish an application to this server with the following location:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -File "c:\Program Files\Citrix\XenApp Server SDK\Citrix.XenApp.Sdk.ps1" - Launch your new editor
- By default it will not be set up to recognise XenApp commands while editing, so use the command:
Add-PSSnapin Citrix*
You can use Notepad to edit your PowerShell scripts – but that’s not very fun so let’s publish an application “Windows PowerShell Integrated Scripting Environment (ISE)”. This is a very good editor for developing PowerShell scripts, with a nice window to run them in and some basics like automatic colouring of your code. Of course, you can skip this if you like Notepad…
- Login to your XenApp 6 server
- Go to Command Prompt
- Enter this command:
servermanagercmd -install PowerShell-ISE - It will whinge and then work anyway:
- Publish a hosted application on your farm at:
c:\windows\sysWOW64\WindowsPowerShell\v1.0\PowerShell_ISE.exe - Again, you will need to run the command “Add-PSSnapin Citrix*” to preload all the commands for XenApp. In ISE, you can enter quick commands like this in the bottom window, then build up your scripts in the tabbed top window. The middle window displays any console output.
Some useful basic commands for XenApp in PowerShell
I’m planning a much bigger post on this, but in the meantime, here’s some really basic bits of code to show you what you can do with PowerShell…
Display the farm name
$farm = Get-XAFarm
$farm.FarmName
Display the zone name data collector for a zone (the zone of the XenApp server you run on of course)Remember if you are saving any of these its best to put the command “Add-PSSnapin Citrix*” at the top to make sure it always has the Citrix commands loaded. You should really consider signing your scripts as well – which is an art in itself!
$zone = get-XAzone
$zone.ZoneName
$zone.DataCollector
Display counts for the total number of active and disconnected sessions in the farm
Get-XASession -Farm | where-object {$_.State -eq "Active" } | Measure-object
Get-XASession -Farm | where-object {$_.State -eq "Disconnected" } | Measure-object
Display a list of all your farm servers, listed alphabetically, with the number of sessions on each:
$servers = Get-XAServer -full
$output = "`nServers: `n"
foreach($server in $servers | sort-object ServerName){
$output+=$server.ServerName + " " + $server.SessionCount + "`n"
}
$output
0 comments:
Post a Comment