%3CLINGO-SUB%20id%3D%22lingo-sub-246559%22%20slang%3D%22en-US%22%3EGenerating%20Per%20Device%20license%20usage%20reports%20for%20TS%20License%20Servers%20running%20Windows%20Server%202008%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-246559%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20CloudBlogs%20on%20Aug%2C%2009%202007%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EIn%20an%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fts%2Farchive%2F2007%2F08%2F06%2Fterminal-services-per-user-licensing-usage-tracking.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20earlier%20post%20%3C%2FA%3E%20%2C%20we%20showed%20how%20to%20create%20a%20per%20user%20license%20usage%20report%20in%20Windows%20Server%202008.%20Below%20we%20show%20how%20to%20create%20a%20per%20device%20license%20usage%20report.%3C%2FP%3E%0A%20%20%3CP%3EOn%20Windows%20Server%202003%2C%20a%20Per%20Device%20Terminal%20Services%20Client%20Access%20License%20(TS%20CAL)%20usage%20report%20could%20be%20generated%20using%20the%20%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F317592%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Lsreport%20tool%20%3C%2FA%3E%20.%20In%20Windows%20Server%202008%2C%20the%20Lsreport%20tool%20is%20not%20supported.%20Instead%2C%20use%20the%20TS%20Licensing%20WMI%20interface%20to%20generate%20a%20Per%20Device%20TS%20CAL%20usage%20report%20in%20Windows%20Server%202008.%3C%2FP%3E%0A%20%20%3CP%3ETo%20generate%20a%20Per%20Device%20TS%20CAL%20usage%20report%2C%20you%20need%20to%20enumerate%20the%20Win32_TSIssuedLicense%20class%20instances%20on%20the%20license%20server.%20The%20following%20is%20a%20simple%20script%20that%20displays%20a%20list%20of%20issued%20Per%20Device%20TS%20CAL%20from%20a%20given%20license%20server%20with%20details%20like%20expiration%20date%2C%20etc.%3C%2FP%3E%0A%20%20%3CP%3E'----------------------------------------------------------------------------%3C%2FP%3E%0A%20%20%3CP%3E'%20Script%20to%20generate%20TS%20Per-Device%20license%20usage%20report.%3C%2FP%3E%0A%20%20%3CP%3E'%20Requires%20Administrator%20privilege%20on%20the%20license%20server.%3C%2FP%3E%0A%20%20%3CP%3E'%20Works%20only%20with%20WS08%20TS%20License%20Server%2C%20as%20there%20is%20no%20WMI%3C%2FP%3E%0A%20%20%3CP%3E'%20interface%20for%20TS%20Licensing%20on%20earlier%20versions.%3C%2FP%3E%0A%20%20%3CP%3E'----------------------------------------------------------------------------%3C%2FP%3E%0A%20%20%3CP%3ESET%20Args%20%3D%20WScript.Arguments%3C%2FP%3E%0A%20%20%3CP%3ENameSpace%20%3D%20%22rootcimv2%22%3C%2FP%3E%0A%20%20%3CP%3EClassName%20%3D%20%22Win32_TSIssuedLicense%22%3C%2FP%3E%0A%20%20%3CP%3EIF%20Args.Length%20%26gt%3B%202%20THEN%3C%2FP%3E%0A%20%20%3CP%3EHelp%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.QUIT(1)%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3EIF%20Args.Length%20%3D%201%20THEN%3C%2FP%3E%0A%20%20%3CP%3EHelp%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.QUIT(1)%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3EIF%20Args.Length%20%3D%202%20THEN%3C%2FP%3E%0A%20%20%3CP%3E'%20Checking%20if%20Server%20Name%20has%20been%20provided%3C%2FP%3E%0A%20%20%3CP%3ECompResult%20%3D%20strComp(Args(0)%2C%20%22-server%22%2C1)%3C%2FP%3E%0A%20%20%3CP%3EIF%20CompResult%20%3D%200%20THEN%3C%2FP%3E%0A%20%20%3CP%3EServerName%20%3D%20Args(1)%3C%2FP%3E%0A%20%20%3CP%3EELSE%3C%2FP%3E%0A%20%20%3CP%3EHelp%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.QUIT(1)%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3EELSE%3C%2FP%3E%0A%20%20%3CP%3E'%20if%20argc.length%20%3D%200%2C%20no%20arg%20supplied%3C%2FP%3E%0A%20%20%3CP%3EServerName%20%3D%20%22.%22%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3EGeneratePerDeviceReport%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.QUIT%3C%2FP%3E%0A%20%20%3CP%3E'----------------------------------------------------------------------------%3C%2FP%3E%0A%20%20%3CP%3E'%20FUNCTIONS%3C%2FP%3E%0A%20%20%3CP%3E'----------------------------------------------------------------------------%3C%2FP%3E%0A%20%20%3CP%3ESUB%20Help()%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22Usage%3A%20GeneratePerDeviceReport.vbs%20%5B-Server%20ServerName%5D%22%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22%20If%20no%20ServerName%20is%20provided%2C%20then%20report%20generation%22%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22%20is%20attempted%20at%20host%20machine%22%3C%2FP%3E%0A%20%20%3CP%3EEND%20SUB%3C%2FP%3E%0A%20%20%3CP%3ESUB%20GeneratePerDeviceReport()%3C%2FP%3E%0A%20%20%3CP%3EErr.Clear%3C%2FP%3E%0A%20%20%3CP%3ESet%20ObjWMIService%20%3D%20GetObject(%22winmgmts%3A%22%20%26amp%3B%20ServerName%20%26amp%3B%20%22%22%20%26amp%3B%20NameSpace%20)%3C%2FP%3E%0A%20%20%3CP%3EIF%20ERR.NUMBER%20%26lt%3B%26gt%3B%200%20THEN%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22Unable%20to%20connect%20to%20the%20Namespace%22%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.QUIT(2)%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3ESet%20ObjectSet%20%3D%20ObjWMIService.ExecQuery%20(%22Select%20*%20from%20Win32_TSIssuedLicense%22)%3C%2FP%3E%0A%20%20%3CP%3EReportCountBefore%20%3D%20ObjectSet.Count%3C%2FP%3E%0A%20%20%3CP%3E'%20No%20Reports%20are%20present%3C%2FP%3E%0A%20%20%3CP%3EIF%20ObjectSet.Count%20%3D%200%20THEN%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22No%20Per%20Device%20license%20issued%22%3C%2FP%3E%0A%20%20%3CP%3EWScript.Quit(5)%3C%2FP%3E%0A%20%20%3CP%3EEND%20IF%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20%22KeyPackID%2CLicenseID%2CIssuedToMachine%2CHWID%2CExpiryDate%22%3C%2FP%3E%0A%20%20%3CP%3EFOR%20EACH%20ObjectClass%20IN%20ObjectSet%3C%2FP%3E%0A%20%20%3CP%3EWSCRIPT.ECHO%20ObjectClass.KeyPackId%20%26amp%3B%20%22%2C%22%20%26amp%3B%20ObjectClass.LicenseId%20%26amp%3B%20%22%2C%22%20%26amp%3B%20ObjectClass.sIssuedToComputer%20%26amp%3B%20%22%2C%22%20%26amp%3B%20ObjectClass.sHardwareId%20%26amp%3B%20%22%2C%22%20%26amp%3B%20ObjectClass.ExpirationDate%3C%2FP%3E%0A%20%20%3CP%3ENEXT%3C%2FP%3E%0A%20%20%3CP%3EEND%20SUB%3C%2FP%3E%0A%20%20%3CP%3EPer%20device%20license%20usage%20reports%20for%20all%20the%20discoverable%20license%20servers%20can%20be%20generated%20by%20getting%20the%20list%20of%20license%20servers%20using%20WMI%20method%20Win32_TerminalServiceSetting%3A%3AFindLicenseServers%20()%20and%20running%20the%20above%20script%20for%20each%20license%20server.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-246559%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20CloudBlogs%20on%20Aug%2C%2009%202007%20In%20an%20earlier%20post%2C%20we%20showed%20how%20to%20create%20a%20per%20user%20license%20usage%20report%20in%20Windows%20Server%202008.%3C%2FLINGO-TEASER%3E
Occasional Contributor
First published on CloudBlogs on Aug, 09 2007

In an earlier post , we showed how to create a per user license usage report in Windows Server 2008. Below we show how to create a per device license usage report.

On Windows Server 2003, a Per Device Terminal Services Client Access License (TS CAL) usage report could be generated using the Lsreport tool . In Windows Server 2008, the Lsreport tool is not supported. Instead, use the TS Licensing WMI interface to generate a Per Device TS CAL usage report in Windows Server 2008.

To generate a Per Device TS CAL usage report, you need to enumerate the Win32_TSIssuedLicense class instances on the license server. The following is a simple script that displays a list of issued Per Device TS CAL from a given license server with details like expiration date, etc.

'----------------------------------------------------------------------------

' Script to generate TS Per-Device license usage report.

' Requires Administrator privilege on the license server.

' Works only with WS08 TS License Server, as there is no WMI

' interface for TS Licensing on earlier versions.

'----------------------------------------------------------------------------

SET Args = WScript.Arguments

NameSpace = "rootcimv2"

ClassName = "Win32_TSIssuedLicense"

IF Args.Length > 2 THEN

Help

WSCRIPT.QUIT(1)

END IF

IF Args.Length = 1 THEN

Help

WSCRIPT.QUIT(1)

END IF

IF Args.Length = 2 THEN

' Checking if Server Name has been provided

CompResult = strComp(Args(0), "-server",1)

IF CompResult = 0 THEN

ServerName = Args(1)

ELSE

Help

WSCRIPT.QUIT(1)

END IF

ELSE

' if argc.length = 0, no arg supplied

ServerName = "."

END IF

GeneratePerDeviceReport

WSCRIPT.QUIT

'----------------------------------------------------------------------------

' FUNCTIONS

'----------------------------------------------------------------------------

SUB Help()

WSCRIPT.ECHO "Usage: GeneratePerDeviceReport.vbs [-Server ServerName]"

WSCRIPT.ECHO " If no ServerName is provided, then report generation"

WSCRIPT.ECHO " is attempted at host machine"

END SUB

SUB GeneratePerDeviceReport()

Err.Clear

Set ObjWMIService = GetObject("winmgmts:" & ServerName & "" & NameSpace )

IF ERR.NUMBER <> 0 THEN

WSCRIPT.ECHO "Unable to connect to the Namespace"

WSCRIPT.QUIT(2)

END IF

Set ObjectSet = ObjWMIService.ExecQuery ("Select * from Win32_TSIssuedLicense")

ReportCountBefore = ObjectSet.Count

' No Reports are present

IF ObjectSet.Count = 0 THEN

WSCRIPT.ECHO "No Per Device license issued"

WScript.Quit(5)

END IF

WSCRIPT.ECHO "KeyPackID,LicenseID,IssuedToMachine,HWID,ExpiryDate"

FOR EACH ObjectClass IN ObjectSet

WSCRIPT.ECHO ObjectClass.KeyPackId & "," & ObjectClass.LicenseId & "," & ObjectClass.sIssuedToComputer & "," & ObjectClass.sHardwareId & "," & ObjectClass.ExpirationDate

NEXT

END SUB

Per device license usage reports for all the discoverable license servers can be generated by getting the list of license servers using WMI method Win32_TerminalServiceSetting::FindLicenseServers () and running the above script for each license server.