JSI Tip 10066. How can I retrieve the distinguished name of the computer I am logged onto using standard commands?


I have scripted DnComputer.bat to return the distinguished name of the computer you are logged onto your Active Directory  domain from, using standard commands.

The syntax for using DnComputer.bat is:

DnComputer CompDN

Where CompDN is a call directed environment variable that will contain the DN of the computer you are logged onto the domain from.

Example:

When I use DnComputer CompDN

CompDN is set to "CN=JSI009,CN=Computers,DC=JSIINC,DC=COM".

DnComputer.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax Call DnComputer ComputerDN&exit /b 1
if exist "%TEMP%\DnComputer.vbs" goto doit
@echo Set objSysInfo = CreateObject("ADSystemInfo")>"%TEMP%\DnComputer.vbs"
@echo Wscript.Echo objSysInfo.ComputerName>>"%TEMP%\DnComputer.vbs"
:doit
for /f "Tokens=1* Delims=;" %%c in ('cscript //Nologo "%TEMP%\DnComputer.vbs"') do (
 set %1="%%c"
)
exit /b 0



Hide comments

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.
Publish