by fcastillo at 2012-08-31 13:34:34


i really need help now, i know this is an utterly unusual request, but i have been put to a lot
of pressure at work to complete a project that was assigned to me, knowing that i was barely getting
in touch with power shell.
so this is what i would like your help with if at all possible.
thanks to all in advance.

i need to create a script that will help me count .ica sessions in multiple farms,
and output a report in excel with the ammount of sessions per server and the total,
in the event that a server where unaccessible, the script should skip, and come back to
the servers that where unaccessible at the time, and considering that our farm is rather large,
the script should run in batches of 10 servers at a time.

if you guys can help me out with this one i will really appreciate it, anyway, thank you for your time.

this is what i have so far]

[string]$HostFile = “\server\share\hosts.txt”

$arHosts = @(Get-Content $HostFile)
$nCounter = 0

#Loop through the computers.
foreach ($strHost in $arHosts){
Add-PSSnapin Citrix*

if($args.Count -eq 0)
Add-Content output.txt -Value $DataOutput
write-host “Usage: CountICASessions <$strHost>”
exit 1

$sessions = Get-XASession -ServerName $args[0]
$count = ($sessions | ? {$_.Protocol -eq “Ica”}).Count

if($count -eq 0)
Add-Content countresult.txt -Value $DataOutput
write-host "ERROR - No ICA sessions"
exit 2

Add-Content output.txt -Value $DataOutput
write-host "OK - Active ICA sessions: $count"
exit 0
by DonJ at 2012-09-01 08:36:07
Happy to try and help. Can you point to some specific thing you’re having trouble with, or that you don’t know how to do, so that we can help you with that?
by poshoholic at 2012-09-01 09:19:29
Just to second what Don said, the best way to get help from these forums is to be as specific as possible. Posting the script you have so far is good, but we also need to know what exactly you’re having trouble with, what errors you’re seeing if you’re getting any errors, and any other details so that we can point you in the right direction. I also strongly recommend using a subject that identifies what you are trying to do so that others who review the forums can see from the subject whether or not they can help with that particular area. For example, if you’re having trouble creating custom objects, use Creating Custom Objects for the subject. Or if it’s about finding something Xml, use Unable to find information in Xml document as the subject. Otherwise the people who offer assistance on these forums won’t really know where to start.

All that said, based on what information you have provided, it seems you are working with multiple Citrix XenApp server farms (this would be good information to include in the subject line), writing a script with the following requirements:

1. For each farm, identify how many .ica sessions are open on each server.
2. If a server is unaccessible, add it to a queue to check later and try again (how many times do you want to retry for each server?).
3. Check 10 servers at a time.
4. Output the data that is gathered to a CSV file that contains two properties: ServerName (this will contain the name of each server or “Total” for the total of all servers) and SessionCount (this will contain the count of the Ica sessions for each server, or the total count for all servers as the last entry).

That’s helpful, but most people who review this can’t pull a Citrix XenApp server farm out of their back pocket to try running your script. For us to help with we need details about what issue or issues you are running into. So where exactly are you stuck with this script?
by powerschill at 2012-09-13 19:45:11
I actually can pull a Citrix XenApp server farm out of my back pocket. :slight_smile: Its been a little while since your post so I want to see where you are with your current status. Also can you provide the XenApp versions of your farms?