Remote Desktop Users - SMX DataSift Addition - updating the SMS_Def.Mof to include users who have rights to log on remotely
I have been using the SMSExpert.com DataShift modifications for SMS 2003 SP2.
A recent request came in to also gather the ‘Remote Desktop Users’ group.
Below are the script and the MOF edit.
Enjoy
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Created by SMS Expert.com
'Modified by Shaun Cassells
'11/10/2007
'Gathers the 'Remote Desktop Users' group and adds it to WMI
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
option explicit
'Turned off because I use error checking around table deletion
'On Error Resume Next
Dim strPartc, str1, str2, str3, str4
'Turn this true if you want to see command line echo
'Debuging
Dim bEcho: bEcho = False
Dim wbemCimtypeSint16
Dim wbemCimtypeSint32
Dim wbemCimtypeReal32
Dim wbemCimtypeReal64
Dim wbemCimtypeString
Dim wbemCimtypeBoolean
Dim wbemCimtypeObject
Dim wbemCimtypeSint8
Dim wbemCimtypeUint8
Dim wbemCimtypeUint16
Dim wbemCimtypeUint32
Dim wbemCimtypeSint64
Dim wbemCimtypeUint64
Dim wbemCimtypeDateTime
Dim wbemCimtypeReference
Dim wbemCimtypeChar16
wbemCimtypeSint16 = 2
wbemCimtypeSint32 = 3
wbemCimtypeReal32 = 4
wbemCimtypeReal64 = 5
wbemCimtypeString = 8
wbemCimtypeBoolean = 11
wbemCimtypeObject = 13
wbemCimtypeSint8 = 16
wbemCimtypeUint8 = 17
wbemCimtypeUint16 = 18
wbemCimtypeUint32 = 19
wbemCimtypeSint64 = 20
wbemCimtypeUint64 = 21
wbemCimtypeDateTime = 101
wbemCimtypeReference = 102
wbemCimtypeChar16 = 103
Dim oLocation, oServices, oInstances, oObject, oDataObject, oNewObject, oRptObject
Set oLocation = CreateObject("WbemScripting.SWbemLocator")
'Remove classes
Set oServices = oLocation.ConnectServer(, "root\cimv2")
On Error Resume Next
set oNewObject = oServices.Get("SMX_RemoteDesktopUsers")
oNewObject.Delete_
Set oServices = oLocation.ConnectServer(, "root\cimv2\SMS")
Set oNewObject = oServices.Get("SMX_RemoteDesktopUsers")
oNewObject.Delete_
On Error GoTo 0
'Create data class structure
Set oServices = oLocation.ConnectServer(, "root\cimv2")
Set oDataObject = oServices.Get
oDataObject.Path_.Class = "SMX_RemoteDesktopUsers"
oDataObject.Properties_.add "Account", wbemCimtypeString
oDataObject.Properties_.add "Type", wbemCimtypeString
oDataObject.Properties_.add "Domain", wbemCimtypeString
oDataObject.Properties_("Account").Qualifiers_.add "key", True
oDataObject.Put_
'Add Instances to data class
Set oServices = oLocation.ConnectServer(, "root\cimv2")
Dim sComputerName
Dim sQuery
Set oInstances = oServices.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For EACH oObject in oInstances
sComputerName = oObject.Name
If bEcho Then Wscript.ECHO sComputerName
Next
sQuery = "select partcomponent from win32_groupuser where groupcomponent = ""\\\\" & sComputerName & "\\root\\cimv2:Win32_Group.Domain=\""" & sComputerName & "\"",Name=\""Remote Desktop Users\"""""
Set oInstances = oServices.ExecQuery(sQuery)
FOR EACH oObject in oInstances
Set oNewObject = oServices.Get("SMX_RemoteDesktopUsers").SpawnInstance_
strPartc = oObject.PartComponent
str1 = Split(strPartc, ",", -1, 1)
str2 = Split(str1(0), "\", -1, 1)
str4 = Split(str2(4), Chr(34), -1, 1)
' The Account name or Group Name is inside the quotes after the comma
str3 = Split(str1(1), Chr(34), -1, 1)
'if the wmi source name is the same as the domain name inside the quotes, it's a local account
'str2(2) is the wmi source name, str4(1) is the domain name inside the quotes.
If str2(2) = str4(1) Then
oNewObject.Type = "Local"
Else
oNewObject.Type = "Domain"
End If
If bEcho Then Wscript.Echo "oNewObject.Type " & str2(2)
oNewObject.Domain = str4(1)
If bEcho Then Wscript.Echo "oNewObject.Domain " & str4(1)
oNewObject.Account = str3(1)
If bEcho Then Wscript.Echo "oNewObject.Account " & str3(1)
'** DO NO USE **'
''oNewObject.Account = oObject.PartComponent
'** DO NO USE **'
oNewObject.Put_
NEXT
'Create reporting class structure
Set oServices = oLocation.ConnectServer(, "root\cimv2\SMS")
Set oRptObject = oServices.Get("SMS_Class_Template").SpawnDerivedClass_
'Set Class Name and Qualifiers
oRptObject.Path_.Class = "SMX_RemoteDesktopUsers"
oRptObject.Qualifiers_.Add "SMS_Report", True
oRptObject.Qualifiers_.Add "SMS_Group_Name", "Remote Desktop Users"
oRptObject.Qualifiers_.Add "SMS_Class_ID", "MICROSOFT|SMX_RemoteDesktopUsers|1.0"
'Add Reporting Class Properties
oRptObject.Properties_.Add("Account", wbemCimtypeString).Qualifiers_.Add "SMS_Report", True
oRptObject.Properties_("Account").Qualifiers_.Add "key", True
oRptObject.Properties_.Add("Domain", wbemCimtypeString).Qualifiers_.Add "SMS_Report", True
oRptObject.Properties_.Add("Type", wbemCimtypeString).Qualifiers_.Add "SMS_Report", True
oRptObject.Put_