Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting returned data 1

Status
Not open for further replies.
Aug 15, 2006
14
US
Hello All

I use the below query to retrieve a username and extensionattribute7 from Active Directory. attrib7 contains version numbers of backup software installed on end user machines. i.e 6.2, 8.2.1 etc...
I would like to take the info from that attrib and find out how manu total versions of each one listed is, like there are ten 6.2's, fifty 8.2.1.

Is this possible?

Const ADS_UF_ACCOUNTDISABLE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "distinguishedName,sAMAccountName,extensionattribute7,userAccountControl,DisplayName,mail"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 1000
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
strSAM = objRecordSet.Fields("samaccountName")
strattrib7 = objRecordSet.Fields("extensionattribute7").Value
intUAC = objRecordSet.Fields("userAccountControl")
Set objUser = GetObject("LDAP://" & strDN)

If objUser.AccountDisabled = False Then
If strtargetaddress <> "<Not Set>" Then
WScript.Echo strSAM & " ;" & strattrib7
Else
End IF
End If

objRecordSet.MoveNext
Loop
objConnection.Close


Any help is appreciated
 
I'd recommend using a dictionary... if you're referring to the strattrib7 value it would look something like this.

Code:
Set dictData = CreateObject("Scripting.Dictionary")

Do Until objRecordSet.EOF
	strattrib7 = LCase(objRecordSet.Fields("extensionattribute7").Value)
	If dictData.Exists(strattrib7) Then
		dictData(strattrib7) = dictData(strattrib7) + 1
	Else
		dictData.Add strattrib7, 1
	End If
Loop
....code

For Each dictKey in dictData.Keys
	WScript.Echo dictKey & ":  " & dictData(dictKey)
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top