Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Really appreciate your site. Really good site for learning what others do when they run into problems. You guy's are great!!!..."

Geography

Where in the world do Tek-Tips members come from?

LDAP Query to put computer name

OrionCookies (Programmer)
13 Jun 12 14:18
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
OrionCookies (Programmer)
13 Jun 12 15:58
anyone ...thanks for help in advance
ClulessChris (IS/IT--Management)
14 Jun 12 2:30
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!

ClulessChris (IS/IT--Management)
14 Jun 12 2:42
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!

OrionCookies (Programmer)
14 Jun 12 10:27
Hi Cluless, would you please put in right format, i am getting some syntax error..

thanks

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close