|

Citrix: Powershell script to list active thin clients

1 min read

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 powershell 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.

 

 

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 \\servername\sharename\ActiveTCs.txt

 

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.

The following two tabs change content below.

Kees Baggerman

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.
Kees Baggerman

Kees Baggerman

Senior Technical Director at Nutanix - Former Citrix CTP - NVIDIA Enterprise Platform Advisor - 15+ years in EUC

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.

Similar Posts

3 Comments

  1. 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.

    1. 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

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.