By PinkelCreated 01 Apr 2011
My Rating:
Vote
Rating:
Not Rated
Views:9391
Downloads:147
Source:

Count the users on a Citrix Farm (not Published Apps)

Language:  VBScript

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 Yes Windows NT Unknown
Vista Yes Windows 2008 Yes
Description

This script counts every ICA connection (every logged-on user) of every server in the Citrix XenApp Farm. The script has to be started on a XenApp Server and gets every server in the Farm. This gives a view of users on every server, but also it counts the users and shows the total logged-on users on the Farm. The difference with the Access Management Console is, it counts users, not started Published Applications or Desktops. Also it shows the load of the server. When the script is started, on the end it shows the log. But when started with the option /nolog, it will run and log only. Please notice the spaces in line 81 can be diffrent (its depanding of the servername lenght)

Code

Line Numbers: On  Off      Plain Text
'******************************************************************
' naam:     CountCitrixUsers.vbs
' function: First gets every server in Citrix XenApp Farm, then count
'           the users (not Publisched Apps)
' option:   /nolog - don't autostart the notepad with output
'           Change the strLogDir for folder for output
' author:   Pinkel
' versie:   1.4
' datum:    30-11-2009
'******************************************************************
Option Explicit
On Error Resume Next
Dim objWshArgs: Set objWshArgs = Wscript.Arguments
Dim strNoLogShow: strNoLogShow = objWshArgs.Named.Exists("nolog")
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strScriptName: strScriptName = objFSO.GetBaseName(WScript.ScriptName)
Dim strLogDir: strLogDir = "C:\Management\Scripts\Log\"
Const CREATE = True
Const DO_NOT_CREATE = False
Const FOR_READING = 1
Const FOR_APPENDING = 8        
Const ERROR = 1
Const WARNING = 2
Const HIDE_WINDOW = 0
Const WAIT_ON_RETURN = True
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objWshShell: Set objWshShell = CreateObject("Wscript.Shell")
Dim objWshExec
Dim strCMDLine: strCMDLine = objWshShell.ExpandEnvironmentStrings("%COMSPEC%")
Dim strQUser: strQUser = " /C QUSER /server:"
Dim strFilter: strFilter = " | FIND /C "
Dim strUserFilter: strUserFilter = """ica-tcp"""
Dim strQFarm: strQFarm = "QFARM /Load"
Dim strXenAppUsers
Dim strFarmUsers: strFarmUsers = 0
Dim strRunServers: strRunServers = 0
Dim strError: strError = objFSO.GetTempName 
Dim strXenAppFarm: strXenAppFarm = objFSO.GetTempName
Dim strXenUsers: strXenUsers = objFSO.GetTempName
Dim strLogName: strLogName = strLogDir & CustomDateTimeFormat() & "-XenAppUsers.log"
Do while objFSO.FileExists(strLogDir & strLogName)
  strLogName = strLogDir & CustomDateTimeFormat() & "-XenAppUsers.log"
Loop
Dim strNumberName: strNumberName = strLogDir & CustomDateFormat() & "-NumberOfXenAppUsers.log"
Do while objFSO.FileExists(strLogDir & strNumberName)
  strNumberName = strLogDir & CustomDateFormat() & "-NumberOfXenAppUsers.log"
Loop
Dim objLogFile: Set objLogFile = objFSO.OpenTextFile(strLogName,FOR_APPENDING,CREATE)
Dim objNumberFile: Set objNumberFile = objFSO.OpenTextFile(strNumberName,FOR_APPENDING,CREATE)
objWshShell.run "%COMSPEC% /c " & strQFarm & " 2>" & strError & " 1>" & strXenAppFarm, HIDE_WINDOW, WAIT_ON_RETURN
 
If objFSO.FileExists(strXenAppFarm) Then
  With objFSO.OpenTextFile(strXenAppFarm,FOR_READING,DO_NOT_CREATE)
    If .AtEndOfStream <> true then
      Dim strXenAppServers: strXenAppServers = .ReadAll()
      .close
      objFSO.DeleteFile strError,true
      objFSO.DeleteFile strXenAppFarm,true 
    End If
  End With
End If
If isEmpty(strXenAppServers) Then
  If strNoLogShow = True Then
    objLogFile.WriteLine "No Results of a XenApp Farm"
  Else 
    WScript.Echo "No Results of a XenApp Farm"
  End If
Else
  Dim arrServerLines: arrServerLines = Split(strXenAppServers,vbcrlf)
  Dim strServerLine
  For each strServerLine in arrServerLines
    If strServerLine <> "" and strServerLine <> vbcrlf Then
      If Left(strServerLine,1) <> "-" and left(strServerline,11) <> "Server Name" Then
        'Spaces can be diffrent (its depanding of the servername lenght)
		Dim arrServerFields: arrServerFields = split(strServerLine,"             ")
        Dim strXenAppServer: strXenAppServer = arrServerFields(0)
        Dim strLoadBal: strLoadBal = arrServerFields(1)
        Dim strCMDOLine: strCMDOLine = strCMDLine & strQUser & strXenAppServer & strFilter & strUserFilter
        Set objWshExec = objWshShell.Exec(strCMDOLine)
        Do While Not(objWshExec.stdOut.AtEndOfStream)
        	strXenAppUsers = objWshExec.stdOut.ReadLine
        Loop
        Dim strServerLoad
        If strLoadBal = 10000 And strXenAppUsers = 0 Then
          strServerLoad = "is in Maintenance"
        ElseIf strLoadBal = 10000 Then
          strServerLoad = "Load is Full"
          strRunServers = strRunServers + 1
        Else
          strServerLoad = "Load is not Full"
          strRunServers = strRunServers + 1
        End If
        strFarmUsers = strFarmUsers + strXenAppUsers
        objLogFile.WriteLine strXenAppServer & " has " & strXenAppUsers & " Users and the Server " & strServerLoad & " (" & strLoadBal & ")."
      End If
    End If
  Next
  objLogFile.WriteLine "=============================================================="
  Dim strAverage: strAverage = Round (strFarmUsers / strRunServers, 2)
  objLogFile.WriteLine "Citrix XenApp Farm has " & strFarmUsers & " users on " & strRunServers & " active servers (average " & strAverage & " users on a Citrix server)."
  objLogFile.Close
  objNumberFile.WriteLine CustomTimeFormat & " - Citrix XenApp Farm has " & strFarmUsers & " users on " & strRunServers & " active servers (average " & strAverage & " users on a Citrix server)."
  objNumberFile.Close
  If strNoLogShow <> True Then
    objWshShell.run "%SystemRoot%\Notepad.exe " & strLogName
  End If
End If
Function CustomDateTimeFormat()
  CustomDateTimeFormat = year(now) & Right("0" & month(now),2) & Right("0" & day(now),2) & "-" & Right("0" & hour(now),2) & Right("00" & minute(now),2)
End Function
Function CustomDateFormat()
  CustomDateFormat = year(now) & Right("0" & month(now),2) & Right("0" & day(now),2)
End Function
Function CustomTimeFormat()
  CustomTimeFormat = Right("0" & hour(now),2) & ":" & Right("00" & minute(now),2)
End Function

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
henrik
Posted On: 5/17/2011 2:07:59 AM

Thanks for a great script!
How do I edit it for also read disconnected session?
I would like a total of all both active and disconnected (idle) sessions.

Thanks in advance!

billtao
Posted On: 9/29/2018 3:18:42 AM

If you are looking for Coach Outlet Online and want to pay a specific price, the best way to go for that is through Coach Factory Outlet Online.It's much cheaper to do it that way than to try to have a wallet for every Coach Factory Outlet Online you own. The secret to finding Coach Outlet Store for a discounted price is to shop online at an online shop that sales authentic Coach Factory Outlet. Coach Factory Outlet come in a variety of styles, colors and materials. If your dream is to own Coach Outlet Online, then make your dreams come true by going online and finding that handbag that you want. So,are you ready to find out just how you can get those Official Coach Factory Outlet Online? Depending on which Discount NFL Jerseys you happen to be wearing. NFL Jerseys China of the greatest players, hall-of-famers, Champion teams, and rookies are available to the public in authentic and replica styles. No matter if it's the current Cheap Authentic NFL Jerseys, an away Cheap NFL Jerseys From China or even a classic throwback that would make your grandfather proud it's become an American tradition to don your teams colors on Sunday afternoon if only to live vicariously through your favorite player if for just a few short hours. So now, when you see Wholesale NFL Jerseys being worn on Sunday afternoons, you will know that it is for more than just a fashion statement. We have Cheap NFL Jerseys that will fit your style. Get ready for the big game this season with some new Cheap Authentic NFL Jerseys. (More Source: Cheap Football Jerseys,Cheap Jerseys,Cheap Jerseys From China,Cheap Authentic Jerseys,Cheap Jerseys Online)

xiaoou
Posted On: 10/4/2018 5:56:10 AM

20181004 xiaoou stussy hoodie tory burch outlet online reebok shoes ugg boots clearance coach outlet online longchamp outlet store polo ralph lauren swarovski outlet store reebok shoes football shirts coach outlet online swarovski jewellery canada goose outlet puma shoes mulberry uk michael kors outlet mlb jerseys moncler jackets canada goose outlet store kobe shoes cheap ray ban sunglasses longchamp handbags true religion outlet uk christian louboutin shoes tods outlet online pandora charms sale clearance burberry outlet sale true religion jeans ugg boots clearance canada goose jackets uggs outlet canada goose jackets polo ralph lauren polo ralph lauren burberry canada cheap ray ban sunglasses canada goose jackets coach outlet online mlb jerseys ugg boots clearance kate spade outlet online michael kors outlet online adidas yeezy boost barbour women jackets canada goose jackets sale van cleef arpels jewelry cheap nhl jerseys michael kors outlet online cheap football shirts ray ban sunglasses outlet coach outlet online longchamp outlet online mizuno shoes asics running shoes ralph lauren polo ugg canada ferragamo shoes polo outlet factory store mont blanc outlet jordan 12 kd shoes bvlgari outlet canada goose coats nike air huarache cheap ugg boots ferragamo shoes canada goose outlet cheap jordan shoes coach factory outlet coach outlet nike outlet online nfl jerseys polo ralph lauren outlet true religion jeans ugg outlet uggs outlet uggs outlet supreme t shirts ralph lauren shirts cheap jordan shoes christian louboutin shoes true religion jeans sale kobe 9 elite coach outlet online coach outlet store pandora outlet nike outlet store coach outlet jordan 4 michael kors outlet online converse shoes sale cheap jordan shoes nfl jersey wholesale tory burch outlet online uggs outlet ugg boots clearance michael kors outlet christian louboutin shoes adidas nmd runner moncler coats coach outlet store online michael kors outlet clearance canada goose jackets nike shoes outlet christian louboutin shoes supreme t shirts ugg outlet michael kors outlet online air max 90 moncler jackets michael kors outlet clearance oakley sunglasses wholesale balenciaga shoes ugg boots clearance nike air max 1 ralph lauren uk denver broncos jersey ralph lauren polo coach outlet prada sunglasses for women coach factory outlet ugg outlet stores cheap ugg boots michael kors outlet swarovski outlet store cheap oakley sunglasses jordan shoes montblanc pens outlet nike air max soccer jerseys wholesale michael kors wallets for women ugg outlet michael kors bags nike roshe run chrome hearts online store ralph lauren polo michael kors outlet online ugg outlet canada goose outlet giuseppe zanotti shoes chrome hearts outlet store soccer cleats swarovski jewelry cheap oakley sunglasses canada goose outlet store fitflops shoes pandora jewelry hermes outlet store michael kors outlet online polo ralph lauren shirts canada goose coats ralph lauren outlet gucci outlet online coach outlet online cheap oakley sunglasses michael kors uk malone souliers moncler jackets cheap jordan shoes off-white clothing air jordan shoes polo ralph lauren shirts tory burch outlet online pandora charms sale clearance ralph lauren shirts tory burch outlet stores uggs outlet canada goose jackets outlet nike air huarache ugg outlet polo ralph lauren outlet michael kors outlet clearance ysl outlet online swarovski uk christian louboutin shoes suicoke sandals nike air max 90 adidas wings shoes coach factory outlet kate spade sale cheap soccer jerseys supreme t shirts michael kors canada coach outlet canada goose outlet store coach handbags outlet wellensteyn outlet canada goose outlet store longchamp handbags sale polo ralph lauren outlet red bottoms mbt christian louboutin shoes michael kors outlet ralph lauren polo mulberry bags michael kors outlet online ferragamo shoes air jordan shoes cheap jordan shoes cheap ray ban sunglasses cazal outlet michael kors outlet online kate spade handbags adidas shoes coach outlet store online louboutin shoes ugg boots on sale canada goose outlet store pandora charms sale clearance adidas store christian louboutin shoes coach outlet ferragamo outlet canada goose outlet store nike revolution air max 2015 los angeles lakers jerseys cheap oakley sunglasses nhl jerseys coach outlet tory burch outlet online mulberry handbags air jordan shoes christian louboutin outlet christian louboutin outlet moncler outlet online ugg outlet uggs outlet cheap jordan shoes michael kors outlet clearance michael?kors?outlet?online uggs outlet moncler outlet store north face outlet air force 1 shoes cheap ray ban sunglasses hermes birkin bag coach outlet online fred perry polo canada goose outlet store james harden shoes kate spade sale coach outlet online gucci bags fila sneakers michael kors outlet online adidas y3 shoes cheap ugg boots ed hardy outlet ugg outlet coach outlet michael kors outlet online ralph lauren outlet coach outlet online michael kors outlet lacoste shirts ugg boots clearance kate spade air jordan shoes ferragamo shoes nike shoes outlet coach outlet michael kors outlet online michael kors outlet online fitflops kate spade handbags michael kors outlet online michael kors outlet clearance ugg boots ugg outlet north face denail jacket clearance cheap jerseys wholesale oakley sunglasses wholesale oakley sunglasses wholesale mulberry outlet,mulberry handbags outlet fitflops tory burch handbags coach outlet online cheap jerseys wholesale cheap jordans yeezy boost uggs outlet pandora charms sale clearance herve leger dresses foamposite shoes ravens jerseys 49ers jersey canada goose jackets outlet canada goose outlet coach outlet online polo ralph lauren outlet jordan 3 jordan shoes uggs outlet michael kors outlet clearance michael kors factory outlet canada goose jackets manolo blahnik outlet moncler outlet online christian louboutin shoes birkenstock shoes adidas crazy mulberry handbags sale true religion outlet canada goose outlet online broncos jerseys cheap nba jerseys lebron shoes pandora charms sale clearance louboutin outlet burberry outlet store uggs outlet uggs outlet jordan 4 jordan shoes nike air force 1 kate spade handbags salomon outlet christian louboutin shoes swarovski outlet store nike uk store nobis jackets coach outlet burberry outlet online jordan retro cheap ray ban sunglasses fitflops sale clearance ugg boots clearance pandora outlet michael kors outlet clearance coach factory outlet michael kors handbags outlet air jordan retro christian louboutin shoes nike shoes outlet canada goose jackets true religion uk toms outlet uggs clearance hermes outlet store light up shoes christian louboutin shoes true religion jeans coach outlet online michael kors outlet online canada goose outlet pandora charms sale clearance longchamp pas cher michael kors outlet online mulberry handbags nike shoes outlet prada outlet online cheap nba jerseys uggs outlet christian louboutin shoes canada goose jackets new balance outlet coach outlet online canada goose outlet store cheap jordans kate spade sale michael kors outlet uggs outlet canada goose outlet store nfl jerseys mbt gucci outlet store undefeated shoes mcm backpacks texans jerseys canada goose outlet supreme clothing uk michael kors outlet online true religion outlet kobe bryants shoes christian louboutin shoes canada goose jackets uggs outlet cheap jordans free shipping true religion outlet ray ban sunglasses outlet canada goose jackets outlet tory burch outlet online air jordan shoes canada goose outlet store christian louboutin pas cher toms outlet coach factory store uggs outlet uggs outlet ray ban sunglasses outlet cheap jordans for sale air jordan shoes longchamp pliage longchamp pliage cheap ugg boots birkenstock shoes fitflops sale clearance marc jacobs sale canada goose outlet bottega veneta outlet online michael kors outlet online jordan shoes canada goose jackets pandora outlet coach outlet online coach outlet clearance chrome hearts online store christian louboutin shoes mishka snapbacks mulberry handbags adidas outlet online under armour outlet blackhawks jerseys pandora outlet moncler coats ralph lauren outlet coach outlet online true religion jeans pandora charms adidas nmd r1 coach factory outlet coach outlet canada goose jackets cheap nhl jerseys coach outlet online moncler outlet online pandora charms michael kors outlet online hermes belts pandora jewelry polo ralph lauren christian louboutin shoes mbt outlet cartier bracelet san antonio spurs tory burch outlet online louboutin shoes fitflops shoes vans sneakers nike factory store jimmy choo shoes coach factory outlet fitflops ralph lauren outlet ray ban sunglasses mulberry uk cheap basketball shoes cheap ray ban sunglasses true religion outlet coach factory outlet ugg outlet cheap oakley sunglasses coach handbags on sale 2018 world cup jerseys michael kors canada goose canada goose jackets givenchy handbags golden state warriors off white clothing cleveland cavaliers jerseys true religion outlet coach outlet longchamp outlet pandora jewelry camisetas futbol baratas cheap jordan shoes ugg boots clearance longchamp bags ugg outlet coach outlet canada goose outlet store kate spade sale christian louboutin shoes ugg boots tory burch outlet online cheap ray ban sunglasses longchamp handbags polo ralph lauren outlet michael kors outlet online nike shoes outlet fitflops sale clearance ray ban sunglasses outlet true religion outlet coach canada ugg outlet supra shoes sale lacoste polo cheap jordans canada goose outlet store ralph lauren outlet nike blazer pas cher michael kors uk adidas yeezy boost kate spade sale fitflops sale clearance pandora outlet kate spade handbags new york knicks links of london jewellery pandora charms sale clearance michael kors outlet clearance yeezy boost 350 nike air max 2017 michael kors handbags tory burch outlet online ferragamo shoes sale ralph lauren outlet pandora charms sale clearance ecco outlet gucci outlet online christian louboutin shoes ralph lauren femme coach outlet online north face outlet true religion outlet store kate spade outlet online polo outlet online snapbacks wholesale miu miu shoes prada shoes for men moncler outlet store toms outlet canada goose outlet store christian louboutin shoes true religion outlet ferragamo shoes ralph lauren polo canada goose jackets outlet adidas outlet online canada goose jackets nike air max 97 colts jerseys canada goose jackets pandora charms sale clearance cheap nba jerseys jordan shoes michael kors outlet online oakley sunglasses wholesale jordan retro canada goose jackets michael kors outlet clearance ugg boots gucci outlet online true religion outlet mbt coach outlet online mont blanc pens nike air max 90 coach outlet store cheap jerseys wholesale mulberry bags uggs outlet valentino shoes michael kors outlet online 20181004