Hopefully you guys can help with this.
Here's a chunk of code that looks at every user in an OU and plucks out those users' homeDirectory and userPrincipalName attributes:
When I try to run it, though, the error returned is "This key is already associated with an element of this collection."
Basically I need a way to take all the homeDirectory and userPrincipalName attributes that the loop collects for all the users and stick them into two separate dictionary objects. So, at the end, I'd have two dictionary objects, one filled with a list of all users on server01, and one filled with a list of all users on server02.
What would be the best way to go about doing this?
Here's a chunk of code that looks at every user in an OU and plucks out those users' homeDirectory and userPrincipalName attributes:
Code:
strBase = "<LDAP://ou=Users,ou=Site1,ou=Sites,dc=mycompany,dc=com>"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "homeDirectory,userPrincipalName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strHomeDirectory = objRecordSet.Fields("homeDirectory").Value
strUsername = objRecordSet.Fields("userPrincipalName").Value
For Each strHomeDirectory In objRecordSet.Fields
If InStr(strHomeDirectory, "server01") > 0 then
Group1.Add strUsername, "server01"
Else
If InStr(strHomeDirectory, "server02") > 0 Then
Group2.Add strUsername, "server02"
End If
End If
Next
objRecordSet.MoveNext
Loop
When I try to run it, though, the error returned is "This key is already associated with an element of this collection."
Basically I need a way to take all the homeDirectory and userPrincipalName attributes that the loop collects for all the users and stick them into two separate dictionary objects. So, at the end, I'd have two dictionary objects, one filled with a list of all users on server01, and one filled with a list of all users on server02.
What would be the best way to go about doing this?