JSI Tip 9882. How can I retrieve the distinguishedName of the logged on user, using standard commands?

Jerold Schulman

November 3, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted uDN.bat to retrieve the distinguishedName of the logged on user.

The syntax for using uDN.bat is:

call uDN DN

Where DN is a call directed environment variable that will contain the logged on user's distinguishedName, like "CN=Jerold Schulman,CN=Users,DC=JSIINC,DC=COM".

uDN.bat contains:

@echo offif {%1}=={} @echo Syntax: uDN DN&goto :EOFif exist "%TEMP%uDN.VBS" goto [email protected] objSysInfo = CreateObject("ADSystemInfo")>"%TEMP%uDN.VBS"@echo.sUser = 

" ^& objSysInfo.UserName ^&

">>"%TEMP%uDN.VBS"@echo.WScript.Echo sUser>>"%TEMP%uDN.VBS":getDNfor /f "Tokens=*" %%u in ('cscript //nologo "%TEMP%uDN.VBS"') do ( set %1=%%u)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like