• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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

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
bsharath
Asked:
bsharath
  • 5
  • 2
1 Solution
 
AmericomCommented:
What exactly are you trying to do? What "Ntlogin's" are you referring to?
0
 
RobSampsonCommented:
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
 
bsharathAuthor Commented:
Thank u Rob.. Worked perfect...

Any help with this
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_23768338.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bsharathAuthor Commented:
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
 
bsharathAuthor Commented:
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
 
RobSampsonCommented:
Oh yeah, this line:
      strResults = """" & strFullName & """,""" & strNTLogins & """"


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


Regards,

Rob.
0
 
bsharathAuthor Commented:
Thank U Rob works fine...
Any help with other posts...
0
 
bsharathAuthor Commented:
Thank U Rob works fine...
Any help with other posts...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now