Client side XENAPP Session enumeration and selective logoff based on XenApp Server using ICA Client Object (WFICALib)

In my previous post i used AutoIt script to achieve this and now finally figured out to do it using ICA Client Object (WFICALib)
[code language=”powershell” title=”PowerShell Script”]
#the following keys need to be set on 32bit machine; for x64 use wow6432node.
#HKLM\Software\Citrix\ICA Client\CCM\AllowLiveMonitoring=1 (DWORD 32)
#HKLM\Software\Citrix\ICA Client\CCM\AllowSimulationAPI=1 (DWORD 32)
#Use Program Files (x86) for x64 bit machines
[System.Reflection.Assembly]::LoadFile("C:\Program Files\Citrix\ICA Client\WfIcaLib.dll")
$ICO = New-Object WFICALib.ICAClientClass
$ICO.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$EnumHandle = $ICO.EnumerateCCMSessions()
$NumSessions = $ICO.GetEnumNameCount($EnumHandle );
#"Number of live CCM sessions are:" + $NumSessions.tostring()
for( $index = 0; $index -lt $NumSessions ;$index++)
{
$sessionid = $ICO.GetEnumNameByIndex($EnumHandle, $index)
$ICO.StartMonitoringCCMSession($sessionid,$true)
$APPSERVER = $ICO.GetSessionString(0)
if($AppSERVER -match "XA-WIN2K8-EPIC*")
{
"EPIC Session Found running on $AppSERVER; logging off"
$ICO.Logoff()
}
$ICO.StopMonitoringCCMSession($sessionid);
}
$ICO.CloseEnumHandle($EnumHandle)
[/code]
[code language=”text” title=”References” light=”true” collapse=”true”]
ICA Client Object Changes in the Version 11.2 XenApp Plug-in http://support.citrix.com/article/ctx123616
ICA Client Object Reference Guide version 2.5, see: http://support.citrix.com/article/ctx114202
http://blogs.citrix.com/2010/03/02/fun-with-the-ica-client-object-ico-and-net-console-applications/
http://community.citrix.com/pages/viewpage.action?pageId=37388917

ICA connections using Powershell – Part 3


[/code]

Join the Conversation

2 Comments

  1. This is exactly what we was looking for! You really saved our bacon this time Smulpy! To avoid setting the registry keys we ended up executing the ica file inside our application using the LoadIcaFile() and Connect(). This allowed us to later Logoff() the session which was our initial headache. Keep up the good work and keep sharing.

Leave a comment

Leave a Reply to Espen Cancel reply

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

WordPress Appliance - Powered by TurnKey Linux