First Name and Last Name

N

Nik Alleyne

Hi guys and gals
I'm trying to find a way to read the user's first name and last name while
using a batch file. I know I can read the username via %username%, but is
there a way to read the first and last names.

thanks
nik
 
J

Jerold Schulman

Hi guys and gals
I'm trying to find a way to read the user's first name and last name while
using a batch file. I know I can read the username via %username%, but is
there a way to read the first and last names.

thanks
nik
You can retireve the users Full Name using the following:


for /f "Tokens=2*" %%m in ('net user %username% /domain^|Findstr
/C:"Full Name"') do set Fullname=%%n

where the above is one line


You can also use the Active Directory Command-Line Tools, tip 6820 in the 'Tips
& Tricks' at http://www.jsiinc.com, to run:

set qry=dsquery * domainroot -filter
"(&(objectCategory=Person)(objectClass=User)(sAMAccountName=%username%))" -attr
givenName sn
REM The above 3 lines are 1 line
for /f "Skip=1 Tokens=1*" %%u in ('%qry%') do (
set firstname=%%u
set lastname=%%v
)



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top