' Find75Users1.vbs ' VBScript program retrieve the Distinguished Names of 75 objects ' in Active Directory from the sAMAccountName values. ' ' ---------------------------------------------------------------------- ' Copyright (c) 2011 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - January 17, 2011 ' ' This program uses ADO to query Active Directory for 75 objects with ' given values of the sAMAccountName attribute. This program makes 75 ' separate queries of Active Directory. The program tracks how long ' this process takes. The program repeats the 75 queries 10 times at ' random intervals between 10 and 15 minutes apart. ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim intPause, j, arrNames Sub QueryAD(ByVal intCount, ByVal arrNames) Dim adoCommand, adoConnection, strBase, strFilter, strAttributes Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strNTName, strDN Dim lngStart, lngEnd, lngSetup lngSetup = Timer() ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire Active Directory domain. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") strBase = "" ' Comma delimited list of attribute values to retrieve. strAttributes = "distinguishedName" adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False lngStart = Timer() For Each strNTName In arrNames ' Filter on object with specified NT name. strFilter = "(sAMAccountName=" & strNTName & ")" ' Construct the LDAP syntax query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery ' Run the query. Set adoRecordset = adoCommand.Execute ' Enumerate the resulting recordset. Do Until adoRecordset.EOF ' Retrieve values and display. strDN = adoRecordset.Fields("distinguishedName").Value ' Move to the next record in the recordset. adoRecordset.MoveNext Loop adoRecordset.Close Next lngEnd = Timer() ' Clean up. adoConnection.Close Wscript.Echo "-- " & CStr(intCount) & " --" Wscript.Echo FormatNumber((lngStart - lngSetup), 7) Wscript.Echo FormatNumber((lngEnd - lngStart), 7) Wscript.Echo FormatNumber((lngEnd - lngSetup), 7) End Sub ' Specify an array of NT names to be translated. arrNames = Array("r_mueller", "oregon$", "klmueller", "SBecker", _ "SRBecker", "RKWilliard", "FMadison", "TJefferson", "BFranklin", _ "JSmith", "JAdams", "PocketLunch", "School", "minnesota$", _ "JMonroe", "PLUser1", "PLUser2", "guest", "rlmueller", _ "FKaplan", "AReed", "fwilliamson", "JJSmith", "First_Last", _ "LFirst", "W.Smith", "Very Long Name 67890", "User 5", _ "VeryLongUserName4321", "RSmith", "WJohnson", "B#Test", "C_Test", _ "JPolk", "FirstMLast", "SallyCrawford", "JohnAdams", "AlGorney", _ "EZastera3", "EZastera2", "EZastera1", "EKent", "JKirk", _ "michelegeiger", "wrugby", "rrogers", "FJackson", "JackJones", _ "jmpolk", "PLTest", "JamesW", "A_Test", "Administrator", _ "Win2kXP", "TemplateUser", "F(M)Last", "GWashington", _ "VeryLongNameForTesti", "vcmgt0j6", "mo'brian", "PocketLunchSvc$Acct", _ "FMalloy", "fjones", "PL-User3", "Test22", "J Smith", "krbtgt", _ "`~^!@$%&-_", "Burke William", "Wisconsin$", "Washington$", _ "Wyoming$", "Nebraska$", "TsInternetUser", "IUSR_WISCONSIN") Randomize() For j = 1 To 9 Call QueryAD(j, arrNames) intPause = 1000 * CInt(300 + (600 * Rnd())) Wscript.Sleep intPause Next Call QueryAD(j, arrNames)