I want to share experiences and ask for advice. I have created the necessary data class and script to obtain information about the composition of the group ("Users"). All actions are performed based on information from the KB article (link). The question is - how to change the script to return the names of local groups and users belonging to them in one list?
'Declare global variables
dim objNSE, objDCInstance, objDataClass
Dim arrMembership, arrCols()
arrMembership = GetGroupMembership("Users")
Redim arrCols(UBound(arrMembership))
dim intMembers, arrRow(1), arrUser
For intMembers = 0 to uBound(arrMembership)
'wscript.echo "User:[" & arrMembership(intMembers) & "]"
'Populate Values - check for backslash in field
if instr(arrMembership(intMembers), "\")>0 then
arrUser = split(arrMembership(intMembers), "\")
arrRow(0) = arrUser(1)
arrRow(1) = arrUser(0)
else
'If no backslash empty domain field and put everything into the user field
arrRow(0) = ""
arrRow(1) = arrMembership(intMembers)
end if
'Add Row to arrCols
arrCols(intMembers) = arrRow
Next
'Create instance of Altiris NSE component
set objNSE = WScript.CreateObject ("Altiris.AeXNSEvent")
' Set the header data of the NSE
' Please don't modify this GUID
objNSE.To = "{1592B913-72F3-4C36-91D2-D4EDA21D2F96}"
objNSE.Priority = 1
'Create Inventory data block. Here assumption is that the data class is already configured on server
set objDCInstance = objNSE.AddDataClass("LocalUsersGroup") ' -THIS IS THE NAME OF THE DATACLASS
set objDataClass = objNSE.AddDataBlock(objDCInstance)
Dim intCol
For intCol = 0 to uBound(arrCols)
AddInventoryRow(arrCols(intCol))
Next
' Send the NSE data to the NS server
objNSE.SendQueued
'Functions down here to make it easier to understand
Function GetGroupMembership(strGroupName)
'Returns an array with members of a given local group in format Domain\UserName
dim colGroups, objGroup, objUser, strUsers
strUsers = ""
Set colGroups = GetObject("WinNT://.")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
If objGroup.Name = strGroupName Then
For Each objUser in objGroup.Members
dim strUser
'strUser = objUser.Name
strUser = objUser.adsPath
strUser = replace(replace(strUser, "WinNT://", ""), "/", "\")
If strUsers = "" Then
strUsers = strUser
Else
strUsers = strUsers & "," & strUser
End If
Next
End If
Next
dim arrUsers
arrUsers = split(strUsers, ",")
GetGroupMembership = arrUsers
End Function
Sub AddInventoryRow(arrData)
'Add a new row
dim objDataRow
set objDataRow = objDataClass.AddRow
Dim intCols
For intCols = 0 To uBound(arrData)
objDataRow.SetField intCols, ToXmlString(arrData(intCols))
Next
End Sub
'Internal Functions
Function ToXmlString(strInput)
Dim strOutput
If (IsNull(strInput)) Then
ToXMLString = strInput
Else
strOutput = Replace(strInput, "&", "&")
strOutput = Replace(strOutput, """", """)
strOutput = Replace(strOutput, "<", "<")
ToXmlString = Replace(strOutput, ">", ">")
End If
End Function