?
Solved

LDAP Logon User Name

Posted on 2009-02-16
3
Medium Priority
?
582 Views
Last Modified: 2012-05-06
I am trying to get a list of users by the logon username that have dialin access checked on a Windows 2003 Domain.   I want the logon name from the domain instead of the users full name (i.e. Doe, Jane)  I want jdoe.  Just don't know what attribute I need to use.
On Error Resume Next
 
Dim objFileSystem, objOutputFile
Dim strOutputFile
 
' generate a filename base on the script name
strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
 
 
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 
 
objCommand.CommandText = _
    "SELECT cn FROM 'LDAP://dc=iforce,dc=local' WHERE objectCategory='user' " & _
        "AND msNPAllowDialin = TRUE"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    'Wscript.Echo objRecordSet.Fields("cn").Value
	If objUser.AccountDisabled = False Then
	objOutputFile.WriteLine(objRecordSet.Fields("cn").Value)  
	End If
 
    objRecordSet.MoveNext
Loop
objOutputFile.Close
 
Set objFileSystem = Nothing
 
WScript.Quit(0)

Open in new window

0
Comment
Question by:iforce
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
irudyk earned 668 total points
ID: 23650155
Instead of SELECT cn
try SELECT sAMAccount
and use .Fileds("sAMAccount") instead of .Fields("cn") throughout the rest of your code
0
 
LVL 58

Assisted Solution

by:tigermatt
tigermatt earned 1332 total points
ID: 23650160

Try this.

-Matt
On Error Resume Next
 
Dim objFileSystem, objOutputFile
Dim strOutputFile
 
' generate a filename base on the script name
strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
 
 
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 
 
objCommand.CommandText = _
    "SELECT cn FROM 'LDAP://dc=iforce,dc=local' WHERE objectCategory='user' " & _
        "AND msNPAllowDialin = TRUE"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    'Wscript.Echo objRecordSet.Fields("cn").Value
        If objUser.AccountDisabled = False Then
        objOutputFile.WriteLine(objRecordSet.Fields("sAMAccountName").Value)  
        End If
 
    objRecordSet.MoveNext
Loop
objOutputFile.Close
 
Set objFileSystem = Nothing
 
WScript.Quit(0)

Open in new window

0
 
LVL 58

Assisted Solution

by:tigermatt
tigermatt earned 1332 total points
ID: 23650165

Sorry, that won't work. You'll need this one instead!

-Matt
On Error Resume Next
 
Dim objFileSystem, objOutputFile
Dim strOutputFile
 
' generate a filename base on the script name
strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
 
 
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 
 
objCommand.CommandText = _
    "SELECT cn, sAMAccountName FROM 'LDAP://dc=iforce,dc=local' WHERE objectCategory='user' " & _
        "AND msNPAllowDialin = TRUE"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    'Wscript.Echo objRecordSet.Fields("cn").Value
        If objUser.AccountDisabled = False Then
        objOutputFile.WriteLine(objRecordSet.Fields("sAMAccountName").Value)  
        End If
 
    objRecordSet.MoveNext
Loop
objOutputFile.Close
 
Set objFileSystem = Nothing
 
WScript.Quit(0)

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 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