Solved

Full names in a txt file. Need to query the full names and get the Ntlogin's from ADS.

Posted on 2008-09-29
8
183 Views
Last Modified: 2010-03-17
Hi,

Full names in a txt file. Need to query the full names and get the Ntlogin's from ADS.
Is there a script that can query each full name in the txt file and get the NTlogin to another file.

Reards
Sharath
0
Comment
Question by:bsharath
  • 5
  • 2
8 Comments
 
LVL 18

Expert Comment

by:Americom
Comment Utility
What exactly are you trying to do? What "Ntlogin's" are you referring to?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
Sharath, this should do it.  I've built in ability to account for a display name possibly having more than one NT Login.

Regards,

Rob.
On Error Resume Next
 

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 objRootDSE = GetObject("LDAP://RootDSE")

strDomain = objRootDSE.Get("defaultNamingContext")
 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile("FullNames.txt", intForReading, False)

strResults = """Full Name"",""NT Logins"""

While Not objFile.AtEndOfStream

	strFullName = objFile.ReadLine

	objCommand.CommandText = _

	    "SELECT samAccountName FROM 'LDAP://" & strDomain & "' WHERE objectCategory='user' " & _

	        "AND displayName='" & strFullName & "'"

	Set objRecordSet = objCommand.Execute	

	strNTLogins = ""

	If Not objRecordSet.EOF Then

		objRecordSet.MoveFirst

		Do Until objRecordSet.EOF

		    If strNTLogins = "" Then

		    	strNTLogins = objRecordSet.Fields("samAccountName").Value

		    Else

		    	strNTLogins = strNTLogins & "," & objRecordSet.Fields("samAccountName").Value

		    End If

		    objRecordSet.MoveNext

		Loop

	End If

	strResults = """" & strFullName & """,""" & strNTLogins & """"

	objRecordSet.Close

Wend

objFile.Close
 

Set objOutputFile = objFSO.CreateTextFile("Results.csv", True)

objOutputFile.Write strResults

objOutputFile.Close
 

MsgBox "Done. Please see Results.csv"

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thank u Rob.. Worked perfect...

Any help with this
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_23768338.html
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Rob in this script is there any restriction. As i get just results to 1 user.

Can you please check. If not found then has to be logged in the csv
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 11

Author Comment

by:bsharath
Comment Utility
Rob in this script is there any restriction. As i get just results to 1 user.

Can you please check. If not found then has to be logged in the csv
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Oh yeah, this line:
      strResults = """" & strFullName & """,""" & strNTLogins & """"


should be this
      strResults = strResults & vbCrLf & """" & strFullName & """,""" & strNTLogins & """"


Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thank U Rob works fine...
Any help with other posts...
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thank U Rob works fine...
Any help with other posts...
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now