How to get a list of users and the client IP addresses using Citrix MFCOM
How to generate a list of users and their clientIP addresses for all the sessions in a Citrix farm
Description
The Citrix administrator often wants to generate a list of users and their client IP addresses for all the sessions in a farm. Citrix admins can use MFCOM API get a list of session and enumerate each session in the list to get username and Client IP for that particular session.
Code Snippet
Save the following code to a file named users.vbs and run it with the command ClientIPandusers.vbs. It lists all users in the farm and their IP addresses:
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm") objFarm.Initialize(1) For Each objSession In objFarm.Sessions WScript.Echo "User name : " & objSession.UserName WScript.Echo "IP Address: " & objSession.ClientAddress Next
Disclaimer
These software applications are provided to you as is with no representations, warranties or conditions of any kind. You may use and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the software application may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the software application fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the software application. In no event should the code be used to support of ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SOFTWARE APPLICATION, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the code.
Comments (2)
Aug 20, 2008
Anonymous says:
Its very usefull one. But i need to extract all the users details in a file lik...Its very usefull one.
But i need to extract all the users details in a file like txt or csv. It should be usefull
Thanks in advance.
Sep 04, 2008
Dale Grimal says:
I had the same need, so I created the following script. Please excuse the "dirty...I had the same need, so I created the following script. Please excuse the "dirty" code as I'm not a programmer, but it suits my needs and even includes a little bit of sanity-checking and commented code
Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile, objFarm, objSession
Dim strDirectory, strFile, strText
strDirectory = "X:"
strFile = "\citrix_user_list.csv"
'strText = "List of Logged in users"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
objFarm.Initialize(1)
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 2
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForAppending, True)
For Each objSession In objFarm.Sessions
strText = "User name " & objSession.UserName & " IP Address " & objSession.ClientAddress
objTextFile.WriteLine(strText)
Next
' Writes strText every time you run this VBScript
objTextFile.Close
' Bonus or cosmetic section to launch explorer to check file
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If
Add Comment