OrionCookies
Programmer
So i have list of full user name (like Bill gates) under c:\TEMP\DisplayName.txt. it reads the Display name and verify with AD and get username. results with csv file.
Now is there way to include computer name in there too. I got this vbscript, but couldn't be able to computer name out. need help help...
On Error Resume Next
Const ForReading =1
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open = "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\TEMP\DisplayName.txt", ForReading)
i = 0
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "DisplayName"
objExcel.Cells(1, 2).Value = "LogonName"
objExcel.Cells(1, 3).Value = "Computer Name"
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
objCommand.CommandText = _
"SELECT saMAccountName FROM 'LDAP://dc=world,dc=AD,dc=domain,dc=COM' WHERE objectCategory='user' " & _
"AND Displayname='" & strNextLine & "'"
objCommand.CommandText = "SELECT Name FROM 'LDAP://cn=saMAccountName,dc=world,dc=AD,dc=domain,dc=COM' WHERE objectCategory = 'computer'"
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
objExcel.Cells(intRow, 1).Value = strNextLine
objExcel.Cells(intRow, 2).Value = objRecordSet.Fields("saMAccountName").Value
objExcel.Cells(intRow, 3).Value = objRecordSet.Fields("name").Value
intRow = intRow + 1
objRecordSet.MoveNext
Loop
Loop
Now is there way to include computer name in there too. I got this vbscript, but couldn't be able to computer name out. need help help...
On Error Resume Next
Const ForReading =1
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open = "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\TEMP\DisplayName.txt", ForReading)
i = 0
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "DisplayName"
objExcel.Cells(1, 2).Value = "LogonName"
objExcel.Cells(1, 3).Value = "Computer Name"
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
objCommand.CommandText = _
"SELECT saMAccountName FROM 'LDAP://dc=world,dc=AD,dc=domain,dc=COM' WHERE objectCategory='user' " & _
"AND Displayname='" & strNextLine & "'"
objCommand.CommandText = "SELECT Name FROM 'LDAP://cn=saMAccountName,dc=world,dc=AD,dc=domain,dc=COM' WHERE objectCategory = 'computer'"
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
objExcel.Cells(intRow, 1).Value = strNextLine
objExcel.Cells(intRow, 2).Value = objRecordSet.Fields("saMAccountName").Value
objExcel.Cells(intRow, 3).Value = objRecordSet.Fields("name").Value
intRow = intRow + 1
objRecordSet.MoveNext
Loop
Loop