I have scripted NTName2DN.bat to convert a user's logon name (sAMAccountName) into their distinguished name (distinguishedName).
The syntax for using NTName2DN.bat is:
\[Call\] NTName2DN NTName NetBIOSDomain DN
Where:
NTName is the user's logon name, like Jerry. NetBIOSDomain is the NetBIOS domain name, like JSIINC DN is a call directed environment variable that will contain the user's distinguishedName.Example:
If you wanted to return the current logged on user's distinguished name:
call NTName2DN %UserName% %USERDOMAIN% DN
@echo %DN%
NTName2DN.bat contains:
@echo off if \{%3\}==\{\} @echo Syntax: NTName2DN NTName NetBIOSDomain DN&goto :EOF setlocal set NTName=%2\%1 set NTName="%NTName:"=%" if exist "%TEMP%\NTName2DN.VBS" goto getDN @echo.Dim objArguments>"%TEMP%\NTName2DN.VBS" @echo.Set objArguments = Wscript.Arguments>>"%TEMP%\NTName2DN.VBS" @echo.Set objTrans = CreateObject("NameTranslate")>>"%TEMP%\NTName2DN.VBS" @echo.objTrans.Init "3", "">>"%TEMP%\NTName2DN.VBS" @echo.objTrans.Set "3", objArguments(0)>>"%TEMP%\NTName2DN.VBS" @echo.Wscript.Echo objTrans.Get("1")>>"%TEMP%\NTName2DN.VBS" :getDN set DN="NOTFOUND" for /f "Tokens=*" %%d in ('cscript //nologo "%TEMP%\NTName2DN.VBS" %NTName%') do ( set DN="%%d" ) endlocal&set %3=%DN%
0 comments
Hide comments