Take the 2-minute tour ×

From the command prompt, how can I get the friendly display name (ie "John Doe" instead of "john.doe") of the domain user that is currently logged in?

share|improve this question
add comment

4 Answers

up vote 5 down vote accepted

Here is a tricky way that I did it using the net command and the find command in a batch file:

set command=net user "%USERNAME%" /domain | FIND /I "Full Name"

FOR /F "tokens=1 delims=" %%A in ('%command%') do SET fullNameText=%%A
set fullName=%fullNameText:Full Name=%
for /f "tokens=* delims= " %%a in ("%fullName%") do set fullName=%%a

The first line stores the command that we want to execute in a variable. It pulls the username from the environment variables and passes that into the net user command as well as the /domain parameter to tell it to pull from the current domain. Then it pipes the result from that, which is a bunch of data on the current user, to a find method which will pull out only the property that we want. The result of the find is in the format "Full Name John Doe". The second line will execute the command and put the result into the variable fullNameText. The third line will remove the "Full Name" part of the result and end up with " John Doe". The fourth line with the for loop will remove all of the leading spaces from the result and you end up with "John Doe" in the fullName variable.

share|improve this answer
We can find the domain name of a computer by running the following commnad from command line. systeminfo | findstr /B /C:”Domain” We can find the logged in user’s domain by using the environment variable ‘Userdomain’. Command for this is given below. echo %userdomain% –  Sathish Aug 29 '12 at 8:49
Great! Works in PowerShell as well: ((net user $env:USERNAME /domain | Select-String "Full Name") -replace "Full Name","").Trim() –  Anders Zommarin Apr 10 '13 at 20:41
I was need to surround %command% with inverted commas in the second line to make it work: ('"%command%"') –  elady Feb 26 at 15:12
add comment

Here's a derivative of skeletank's response that's slightly cleaner that worked for me... (I tried skeletank's response and it didn't work for me the way it was written, thus my answer below.)

SET TNAME="net user %USERNAME% /domain| FIND /I "Full Name""
FOR /F "tokens=3,4 delims=, " %%A IN ('%TNAME%') DO SET DNAME=%%B %%A

Then you can use 'DNAME' anywhere you need like to ouput with an echo or validate with an 'IF' statement. You can flip the '%%B' and '%%A' tokens around to go back to last name first layout. This saves the additional effort used in skeletank's original response.

-TNAME = Temporary Name
-DNAME = Display Name

-Thanks skeletank.

share|improve this answer
works like a charm –  fmuecke May 19 at 12:48
add comment

I built a batch file to do a few things quickly by selecting an action using set p and goto. I'm leaving out the unnecessary parts.

@echo off


echo 5. Find who is on remote PC right now


set /p a=

IF %a%==5 (goto whoson)

REM Whos on
set /p remotecomputername=Enter computer name to see the current user: 
wmic /node:%remotecomputername% computersystem get username
goto begin

I hope it helps.

share|improve this answer
add comment

This should be a clean way using dsquery and dsget without relying on the output of "Full Name", which is language dependent, whereas "fn" seems to work with different language versions of windows.

for /F "tokens=2" %i in ('dsquery user -samid %username% ^| dsget user -L -fn ^| find "fn:"') DO @echo %i

The dsget -L switch gives the listed output "fn: USER" so the only thing left is to grab the second column in the output. find "fn:" is used to get rid of the "dsget succeeded" output.

share|improve this answer
add comment

Your Answer


