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

Batch file to get users name from a nt login name

Hi

There is a command you can use "net user" I belive which will able you to type in a username "tlewis" and it will give you the results to show your full username "terry lewis"

I need to have C:\batch\usernames.txt  and the batch file runs and exports to C:\batch\output.txt.

Does anyone have the script that does this.

Regards


Terry
0
ncomper
Asked:
ncomper
1 Solution
 
sirbountyCommented:
How about a vbscript?
Name it FindUsers.vbs or something similar...
SourceFile = "C:\batch\usernames.txt"
OutputFile = "C:\batch\output.txt"
LDAPDomain = "LDAP://DC=Domain,DC=com"
 
Const ADS_SCOPE_SUBTREE = 2
 
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile(OutputFile)
arrUsers = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
Dim conn : Set conn = CreateObject("ADODB.Connection")
Dim cmd : Set cmd = CreateObject("ADODB.Command")
conn.Provider = "ADsDSOObject"
conn.Open "Active Directory Provider"
Set cmd.ActiveConnection = conn
 
cmd.Properties("Page Size") = 1000
cmd.Properties("SearchScope") = ADS_SCOPE_SUBTREE
 
For Each UserName in arrUsers
  cmd.CommandText = "SELECT givenName, sn FROM '" & LDAPDomain & "' WHERE objectCategory = 'user' AND SAMAccountName = '" & UserName &  "'"
  Dim objRS : Set objRS = cmd.Execute
  objRS.MoveFirst
  Do Until objRS.EOF
    strFullName = objRS.Fields(0) & " " & objRS.Fields(1)
    objOut.WriteLine UserName & vbTab & strFullName
    objRS.MoveNext
  Loop
Next
 
objOut.Close

Open in new window

0
 
ncomperAuthor Commented:
Thanks

Sorry it took a while to copme back
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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