ThinWorld Citrix Knowledgebase

Tuesday, 30 June 2009

Automated TS Cal check Script

The following is a script process i use to check the number of TS Cal in use. (Client Access Licences) Using a script allows me to automate the process to send an email with the licence numbers to our support mailbox each day.

To get output from the Licence server from a command line I use LSREPORT.EXE from the Windows 2003 Resource Kit.

This uses the syntax LSREPORT /F outputfile.txt licenceserver

The Output from this file will contain details on all the issued Terminal Server Client Access licences. (TSCAL's)

The VB Script below basically counts the number of 2003 TSCals issued on a non temporary basis. You may need to edit the licence code in the search to suit your environment. In my example the licence code was A02-5.02-S. It then outputs the total to a text file. In my environment i then use BLAT.EXE (a Lotus Notes Utility) To email the file to a support mailbox where the output can be checked by support staff)

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
WshShell.Exec ("C:\Program Files\Windows Resource Kits\Tools\lsreport.exe /F c:\support\tslic.txt localhost")
Set objFile = objFSO.OpenTextFile("tslic.txt", ForReading)
Set ObjOutPutFile = objFSO.CreateTextFile("TSLic_info.txt",True)
counter = 0

Do Until objFile.AtEndOfStream
strData = objFile.ReadLine
Pos = Instr(StrData,"A02-5.02-S")
If Pos >1 Then
Pos = Instr(StrData,"Temporary")
If Pos = 0 Then
Counter = counter + 1
End If
End If
Loop

ObjOutPutFile.Writeline "TS CAL's in use : " & Counter

objFile.Close
ObjOutPutFile.close