Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
strDomainName = "dc=kt,dc=group,dc=local"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
intRow = 2
objExcel.Cells(1, 1).Value = "Display Name"
objExcel.Cells(1, 2).Value = "SamAccountName"
objexcel.Selection.Autofilter
Set oFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
InputFile = "c:\Anand\displayname.txt"
Set f = oFS.OpenTextFile(InputFile)
StrUser = f.ReadAll
f.Close
arrUsers = Split(StrUser,vbCrLf)
For Each aUser in arrUsers
'strUserCN = "Qian, Lei(Jackey) (TSSHR)"
objCommand.CommandText = "<LDAP://" & strDomainName & ">;(&(objectCategory=person)(object)(displayName=" & aUser & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If Not objRecordset.EOF Then
WScript.Echo objRecordSet.Fields("samAccountName")
End If
objExcel.Cells(intRow, 1).Value = aUser
objExcel.Cells(intRow, 2).Value = objRecordSet.Fields("samAccountName")
intRow = intRow + 1
Next
objexcel.Cells.EntireColumn.AutoFit
objexcel.Cells.EntireRow.AutoFit
objWorkbook.SaveAs "C:\Anand\Disp2Sam.xlsx"
objExcel.Quit
objConnection.Close
Set objRecordSet = Nothing
Set objConnection = Nothing
Set objCommand = Nothing