Clay Calvert said:
VBS would be great. The addresses are in a .CSV file as the first
column, but they can be put into their own text file easily.
Looking for addresses in the list that exist in AD, so both. None of
the addresses in the list 'should' be in AD already.
Thank you very much.
Clay Calvert
(e-mail address removed)
Replace "W" with "L"
This might be a duplicate, I replied to this earlier with a VBS file
attached, but some newsservers block attachments so I thought I would post
again with it pasted inside.
Hi Clay,
Below is a VBS script, this should get you started. Near the top of the
script you will need to change the domain name and the name of the file
containing your email addresses.
This script uses ADSI to query AD using an LDAP filter on the mail attribute
of each user account. For best results run it with CSCRIPT.EXE, not
WSCRIPT.EXE.
Marty
Watch out for line wraps:
Option Explicit
On Error Resume Next
Const ADS_PATH = "DC=yourdomain,DC=com"
Const SEARCH_FILE = "C:\Temp\Test.txt"
Const FOR_READING = 1
Dim objFS, objFile
Dim objADOConnection, objADOCommand
Dim intResult, strResult
Dim strNextLine, arrNextLine
Dim strADResult
Dim DebugMode
DebugMode = True
' Open the text file for reading:
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(SEARCH_FILE, FOR_READING, False)
intResult = Err.Number
strResult = Err.Description
If intResult <> 0 Then
WScript.Echo "Failed to open " & SEARCH_FILE & ", error " & _
CStr(intResult) & " (" & strResult & ")"
WScript.Quit(intResult)
End If
' Open the ADo connection:
Set objADOConnection = CreateObject("ADODB.Connection")
Set objADOCommand = CreateObject("ADODB.Command")
If Err.Number <> 0 Then
WScript.Echo "Failed to create ADO connection, check MDAC installation."
WScript.Quit(Err.Number)
End If
' Open the ADSI connection:
objADOConnection.Provider = "ADsDSOObject"
objADOConnection.Open "Active Directory Provider"
If Err.Number <> 0 Then
WScript.Echo "Failed to open ADSI connection, check AD client
installation."
WScript.Quit(Err.Number)
End If
Set objADOCommand.ActiveConnection = objADOConnection
strNextLine = objFile.ReadLine
While Err.Number = 0
Trace("strNextLine: [" & strNextLine & "]")
If Trim(strNextLine) <> "" Then
arrNextLine = Split(strNextLine, ",")
strADResult = LookupADAccount(ADS_PATH, "mail", arrNextLine(0))
WScript.Echo arrNextLine(0) & "=" & strADResult
End If
strNextLine = objFile.ReadLine
Wend
objFile.Close
Set objFile = Nothing
Set objFS = Nothing
WScript.Quit(0)
Function LookupADAccount(ByVal strADsPath, ByVal strAttributeName, ByVal
strProperty)
Trace("LookupADAccount(" & strAttributeName & ", " & strProperty & ")")
LookupADAccount = "No match"
Dim objRS
Dim strCommand, strBuffer
If Trim(strADsPath) = "" Then
LookupADAccount = "Failed, invalid LDAP DN."
Exit Function
End If
If Left(UCase(strADsPath), 7) = "LDAP://" Then
strADsPath = Right(strADsPath, Len(strADsPath) - 7)
End If
' Compose the search query. See:
'
http://msdn.microsoft.com/library/en-us/netdir/adsi/search_filter_syntax.as
p
strCommand = "select name," & strAttributeName & " from 'LDAP://" & _
strADsPath & "' WHERE " & _
"objectCategory = 'person' " & _
"AND objectClass='user' " & _
"AND " & strAttributeName & "='" & strProperty & "'"
objADOCommand.CommandText = strCommand
Set objRS = objADOCommand.Execute
' Navigate the record set
While Not objRS.EOF
LookupADAccount = objRS.FIELDS("Name")
objRS.MoveNext
Wend
End Function
Sub Trace(ByVal strMessage)
If DebugMode Then WScript.Echo "DEBUG: " & strMessage
End Sub