I have scripted NTName2UPN.bat to convert a user's logon name (sAMAccountName) into their User Principal Name (userPrincipalName).

The syntax for using NTName2UPN.bat is:

\[Call\] NTName2UPN NTName NetBIOSDomain UPN

Where:

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

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

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

If you wanted to return the current logged on user's UPN (User Principal Name)

call NTName2UPN %UserName% %USERDOMAIN% UPN
@echo %UPN%

NTName2UPN.bat contains:

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