Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LDAP Query to put computer name

Status
Not open for further replies.

OrionCookies

Programmer
May 5, 2005
43
0
0
US
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
 
I think you'll need to query for the workstation where the 'isduser' attribute matches the user, basicaly the other way around from how you're trying now.

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Or you be able to:
Code:
Dim WS, Workstations as Variant
Dim User             as IADsUser
Dim sResult          as String

Set user = GetObject('ADsPath')
Workstations = User.GetEx("isdworkstaion")
For Each WS is Workstations
    sResult = sResult & WS & VbCrLf
Next

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Hi Cluless, would you please put in right format, i am getting some syntax error..

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top