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
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 18

Expert Comment

by:Americom
ID: 22599013
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
ID: 22601204
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
ID: 22602389
Thank u Rob.. Worked perfect...

Any help with this
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_23768338.html
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 11

Author Comment

by:bsharath
ID: 22602538
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 11

Author Comment

by:bsharath
ID: 22602539
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
ID: 22602771
Oh yeah, this line:
      strResults = """" & strFullName & """,""" & strNTLogins & """"


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


Regards,

Rob.
0
 
LVL 11

Author Comment

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

Author Comment

by:bsharath
ID: 22602825
Thank U Rob works fine...
Any help with other posts...
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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