

If you agree, I’d like to talk about your work on my blog (which is GEBRE: Starting from your code, I created a set of macro that I’m using to monitorize my job on huge active directory. GetAdsProp = objRecordSet.Fields(ReturnField) ‘ Not a multi-value field: just return the value. ‘ Remove trailing separator character(s).

VarProp = objRecordSet.Fields(ReturnField).Value ‘ Will be an variant-array if multi-value field. GetAdsProp = “not found” ‘ no records returned “ (&(objectCategory=” + ObjectType + “)” & _ Returns ‘CN=CitrixAdmin,OU=Security,OU=Groups,DC=TestAD,DC=local CN=SQLDBA,OU=Security,OU=Groups,DC=TestAD,DC=local CN=VMwareAdmin,OU=Security,OU=Groups,DC=TestAD,DC=local CN=3rdLineAdmin,OU=Security,OU=Groups,DC=TestAD,DC=local CN=TestAdministrators,CN=Users,DC=TestAD,DC=local’įunction GetAdsProp(ByVal SearchField As String, ByVal SearchString As String, ByVal ReturnField As String, Optional ByVal ObjectType As String = “User”, Optional ByVal strSepChar As String = “ ”) As String =GetAdsprop(“cn” “MyWindowsXPComputer” “operatingSystem” ”computer”) The fourth (optional) parameter defaults to “ ” but can be any string and is used as seperator string between the multivalues. The third (optional) parameter defaults to “User” but can be any valid object. To get it working i’ve added two extra optional parameters I’ve moddified the function so it works with multi-valued fields (MemberOf, ObjectClass etc.) and with other objects, such as Group or Computer. Set objUser = GetObject(“LDAP://” & objRecordSet.Fields(ReturnField)) GetStatus = “not found” ‘ no records returned “(” & SearchField & “=” & SearchString & “)) ” & SearchField & “,” & ReturnField & “ subtree” ‘ Search the AD recursively, starting at root of the domain Set objCommand = CreateObject(“ADODB.Command”) ObjConnection.Open “Provider=ADsDSOObject ” Set objConnection = CreateObject(“ADODB.Connection”) StrDomain = GetObject(“LDAP://rootDSE”).Get(“defaultNamingContext”) ‘ Get the domain string (“dc=domain, dc=local”) I have added a function of my own to determine whether an account is enabled or disabled.įunction GetStatus(ByVal SearchField As String, ByVal SearchString As String) As String GetAdsProp = objRecordSet.Fields(ReturnField) ' return value GetAdsProp = "not found" ' no records returned

"(" & SearchField & "=" & SearchString & ")) " & SearchField & "," & ReturnField & " subtree" ' Search the AD recursively, starting at root of the domain ObjCommand.ActiveConnection = objConnection Set objCommand = CreateObject("ADODB.Command") ObjConnection.Open "Provider=ADsDSOObject " Set objConnection = CreateObject("ADODB.Connection") StrDomain = GetObject("LDAP://rootDSE").Get("defaultNamingContext") ' Get the domain string ("dc=domain, dc=local") Function GetAdsProp(ByVal SearchField As String, ByVal SearchString As String, ByVal ReturnField As String) As String
