Jump to content

Recommended Posts

I'm building a script to export all idle sessions in Citrix to Excel; so I have an overview

of the load on all servers from the Citrix Farm.

This is the script

Option Explicit

Dim objFarm, objSession, SessionList, tlst, tdis, tcur, t1, t2, minutes, i, fc
Dim SessionState
SessionState = Array("Unknown", _
"Active", _
"Connected", _
"Connecting", _
"Shadowing", _
"Disconnected", _
"Idle", _
"Listening", _
"Resetting", _
"Down", _
"Init")
Dim objFSO, objTextFile
Dim arrSessionsA, arrSessionsB, arrSessionInfoA, arrSessionInfoB
Dim strText, strSession, strSessionState, strCurDT, strCurDTcln, strDataOutFile2
Dim iA, iB
Dim duplicate
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const DataOutFile1 = "Idle_Sessions.csv"
Const DataInFile = "Idle_Sessions.csv"

strCurDT = now
i = 1
fc = 0
do until fc = 4
if Mid(strCurDT, i, 1) = "/" Then
fc = fc + 1
strCurDTcln = strCurDTcln & "-"
else
if Mid(strCurDT, i, 1) = ":" Then
fc = fc + 1
strCurDTcln = strCurDTcln & "-"
else
if Mid(strCurDT, i, 1) = " " Then
strCurDTcln = strCurDTcln & "_"
else
strCurDTcln = strCurDTcln & Mid(strCurDT, i, 1)
end if
end if
end if
i = i + 1
loop
strCurDTcln = strCurDTcln & Mid(strCurDT, i, 1)
strCurDTcln = strCurDTcln & Mid(strCurDT, i + 1, 1)
strDataOutFile2 = strCurDTcln & "_Idle_Sessions_filtered.csv"

'open file in Append mode
Set objFSO = CreateObject("scripting.filesystemobject")
Set objTextFile = objFSO.OpenTextFile(strDataOutFile2, ForAppending, True)
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
' Initialize the farm object.
objFarm.Initialize(MetaFrameWinFarmObject)

Set SessionList = objFarm.Sessions
For Each objSession In SessionList
Set tlst = objSession.LastInputTime(TRUE)
Set tdis = objSession.DisconnectTime(TRUE)
Set tcur = objSession.CurrentTime(TRUE)

strSessionState = SessionState(objSession.SessionState)
t2 = tcur.minute + tcur.hour*60



if strSessionState = "Active" Then
t1 = tlst.minute + tlst.hour*60
minutes = t2 - t1
If Minutes > 120 Then
Minutes = 0
End if
End if


if strSessionState = "Disconnected" Then
t1 = tdis.minute + tdis.hour*60
minutes = t2 - t1 + 120
If Minutes > 240 Then
Minutes = 240
End if

If Minutes < 0 Then
Minutes = 0
End if
End if

'write session info to file

objTextFile.writeline (objSession.ServerName & "," & objSession.UserName & "," & _
objSession.SessionName & "," & CStr(objSession.SessionID) & "," & _
objSession.ClientName & "," & strSessionState & "," & Minutes)
Next

'close file
objTextFile.close

'open file for Reading into sort arrays
Set objTextFile = objFSO.OpenTextFile(strDataOutFile2, ForReading, True)
strText = objTextFile.ReadAll
objTextFile.Close

Set objTextFile = objFSO.OpenTextFile (strDataOutFile2, ForWriting, True)
arrSessionsA = Split(strText, vbCrLf)
arrSessionsB = Split(strText, vbCrLf)
iA = 0
duplicate = 0
do until arrSessionsA(iA) = ""
arrSessionInfoA = Split(arrSessionsA(iA), ",")
iB = iA + 1
do until arrSessionsA(iB) = ""
arrSessionInfoB = Split(arrSessionsB(iB), ",")
'compare username AND server AND sessionid AND workstation name
if arrSessionInfoA(1) = arrSessionInfoB(1) AND _
arrSessionInfoA(0) = arrSessionInfoB(0) AND _
arrSessionInfoA(3) = arrSessionInfoB(3) AND _
arrSessionInfoA(4) = arrSessionInfoB(4) then
duplicate = 1
exit do
end if
iB = iB +1
loop
if duplicate = 1 then
duplicate = 0
else
objTextFile.WriteLine (arrSessionsA(iA))
end if
iA = iA + 1
loop
objTextFile.Close


I Receive an error on line 54

"Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")"

Can someone help me?

Thx

Edited by verlegenmanneke
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...