Q. How can I convert a user's logon name (sAMAccountName) into their Display Name (displayName)?

I have scripted NTName2DspNm.bat to convert a user's logon name (sAMAccountName) into their Display Name (displayName).

The syntax for using NTName2DspNm.bat is:

\[Call\] NTName2DspNm NTName NetBIOSDomain DispNm


NTName        is the user's logon name, like Jerry.

NetBIOSDomain is the NetBIOS domain name, like JSIINC

DispNm        is a call directed environment variable that will contain the user's displayName.

If you wanted to return the current logged on user's Display Name:

call NTName2DspNm %UserName% %USERDOMAIN% DispNm
@echo %DispNm%

NTName2DspNm.bat contains:

@echo off
if \{%3\}==\{\} @echo Syntax: NTName2DspNm NTName NetBIOSDomain DisplayName&goto :EOF
set NTName=%2\%1
set NTName="%NTName:"=%"
if exist "%TEMP%\NTName2DspNm.VBS" goto getDspNm
@echo.Dim objArguments>"%TEMP%\NTName2DspNm.VBS"
@echo.Set objArguments = Wscript.Arguments>>"%TEMP%\NTName2DspNm.VBS"
@echo.Set objTrans = CreateObject("NameTranslate")>>"%TEMP%\NTName2DspNm.VBS"
@echo.objTrans.Init "3", "">>"%TEMP%\NTName2DspNm.VBS"
@echo.objTrans.Set "3", objArguments(0)>>"%TEMP%\NTName2DspNm.VBS"
@echo.Wscript.Echo objTrans.Get("4")>>"%TEMP%\NTName2DspNm.VBS"
set DspNm="NOTFOUND"
for /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%\NTName2DspNm.VBS" %NTName%') do (
 set DspNm="%%d"
endlocal&set %3=%DspNm%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.