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


<b>NTName</b>        is the user's logon name, like Jerry.

<b>NetBIOSDomain</b> is the <b>NetBIOS</b> domain name, like JSIINC

<b>DispNm</b>        is a <a href="/article/tips/tip.aspx?id=5535">call directed environment variable</a> that will contain the user's <b>displayName</b>.

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%