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
LVL 5
ncomperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ncomperAuthor Commented:
Thanks

Sorry it took a while to copme back
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.