Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find domain user first, last name by his network i 1

Status
Not open for further replies.

ggolub

Programmer
Jan 5, 2005
13
US
Hello Forum

I need to find first, last user name by his network id.
I currently do it by using mmc snap-in called Domain users and computers browser.
It's window program but I need to do it in a script.

Thank you, Gene.
 
This should at least get you started:
Code:
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
'Create output file
Set fs = CreateObject ("Scripting.FileSystemObject")
filePath = "c:\temp\Names.txt"
Set outFile = fs.CreateTextFile (filePath)
outFile.Close
userID=InputBox("Enter user id ")
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRootDSE=GetObject("LDAP://RootDSE")
strDNSDomain=objRootDSE.Get("defaultNamingContext")
strTarget="LDAP://" & strDNSDomain

objCommand.CommandText = _
    "SELECT sAMAccountname, displayName FROM '" & strTarget & "' WHERE objectCategory='user' and sAMAccountName='" & userID & "'"
Set objRecordSet = objCommand.Execute
Set ts = fs.OpenTextFile(filePath,8)
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    LoginID = objRecordSet.Fields("sAMAccountname").Value
    displayName = objRecordSet.Fields("displayName").Value
    If IsNull(displayName) Then
       displayName=" "
    End If
    objRecordSet.MoveNext
    ts.WriteLine LoginID & " - " & displayName
Loop
ts.Close
MsgBox "Script has completed..."
WScript.Quit
 
thKidd,

I've got message back. Can you advise please.
C:\Working\de1\vbs\vb1.vbs(17, 1) Active Directory: The directory property cannot be found in the cache.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top