Const ForReading = 1
Const ADS_SCOPE_SUBTREE = 2
strInput = "c:\scripts\addresses.txt"
strOutput = "c:\scripts\output.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(strInput, ForReading)
strText = objInputFile.ReadAll
objInputFile.Close
Set objOutputFile = objFSO.CreateTextFile(strOutput)
Set objRoot = GetObject("LDAP://RootDSE")
strDNSDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
adoCommand.Properties("Page Size") = 1000
adoCommand.Properties("Timeout") = 300
adoCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
arrAddresses = Split(strText, vbCrLf)
For Each strAddress In arrAddresses
strAddress = Trim(strAddress)
If strAddress <> "" Then
adoCommand.CommandText = "SELECT ADsPath FROM '" & strDNSDomain & _
"' WHERE mail='" & strAddress & "' OR proxyAddresses='*" & _
strAddress & "*'"
Set adoRecordset = adoCommand.Execute
If adoRecordset.EOF Then
objOutputFile.WriteLine strAddress & VbTab & "Not Found"
End If
Do Until adoRecordset.EOF
objOutputFile.WriteLine strAddress & VbTab & "Found"
adoRecordset.MoveNext
Loop
End If
Next
|