Citrix: Powershell script to list active thin clients

Share Button

I was working on a project and one of the sys admins wanted to display which thin clients where logged on, so we made a script to export all active thin clients to a txt file. He could make a script that would enumerate that txt file into HTML to display the occupied thin clients on a screen at the entrance so employees could determine which client they could use that day.

 

[codesyntax lang=”powershell” lines=”normal” container=”div”]

set-executionpolicy remotesigned

if (Get-PSSnapin Citrix.XenApp.Commands -ea 0)
{
	Write-Host "Citrix.XenApp.Commands snapin already loaded" -ForegroundColor Yellow
}
else
{
	if (Get-PSSnapIn "Citrix.XenApp.Commands" -registered -ea 0)
	{
		Write-Host "Loading Citrix.XenApp.Commands snapin..." -ForegroundColor Yellow
		Add-PSSnapin "Citrix.XenApp.Commands"
	}
}

Function Global:Get-CtxCommand
{
	param([string[]] $Name = "*")
	Get-Command $Name -CommandType Cmdlet, Function `
		-Module Citrix.XenApp.Commands |
		Sort Noun, Verb | Out-Host -Paging
}

Get-XASession -Farm | where { $_.Protocol -eq "Ica" -and $_.State -eq "Active" -and $_.ClientName -ne $null -and $_.ClientName -like "TCL*" } | Format-List -Property ClientName | Out-File \servernamesharenameActiveTCs.txt

[/codesyntax]

Here’s the script, it’s pretty straight forward: It gets the Citrix.XenApp.Commands snapin if it’s not already in place and lists the information based on active ICA sessions and the only when the client name starts with TCL (Thin Client names based on the naming conventions for this customer).

Output is as following:

ClientName : TCL0004

ClientName : TCL0003

ClientName : TCL0001

ClientName : TCL0002

ClientName : TCL0008

I can’t published the script to enumerate the txt file as it contains to much customer details but I’m sure this is a good start to create the same interface for your users. In this case we used RES Automation Manager to run the script every 5 minutes so employees would know where they could work.

Share Button
  1. Alain AssafAlain Assaf02-15-2012

    If you have EdgeSight installed, you can run some queries to find the thin client devices that are connecting to your Citrix farm(s). I go into detail in this blog post: http://edgesightunderthehood.com/2011/07/06/reporting-on-non-pc-devices/

    Thanks,
    Alain

  2. Jeff WoutersJeff Wouters02-13-2012

    Hi Kees,

    The executionpolicy for PowerShell is something that, in my opinion, should be set by a policy and not in each script. Now you would get a message where you would have to confirm that you want to change the exectution policy.
    But in case you do want this to be included in your sript, some recommendations:
    To avoid that nasty confirmation message, use the -force parameter.
    Set the execution policy on the leven you desire. Right now the default (LocalMachine) will be used where (i think) process or currentuser level should suffice in this case?

    And last… very good idea and code 😀

    Jeff.

    • k.baggermank.baggerman02-22-2012

      Jeff,

      I agree on setting this via GPO but sometimes you just don’t have access to these GPO’s or sys admins don’t want to set this so that’s why I’ve added the first line, thanks for the tips on the confirmation message and the execution policy level.

      Regards,

      Kees

Leave a Reply to Jeff Wouters Click here to cancel reply.