Skip navigation

JSI Tip 9435. How can I return the NetBIOS and distinguished name of all computers in my Active Directory domain?

NOTE: See How can I return the NetBIOS and distinguished name of all computers in my Active Directory domain, using built-in commands?

Using ADFind.exe freeware, I have scripted ADComp.bat to return the NetBIOS and distinguished name of all the computers in the domain you are logged on to.

The syntax for using ADComp.bat is:

for /f "Tokens=1* Delims=;" %%c in ('call ADComp') do (
 set name=%%c
 set dn=%%d
 . . .
)
NOTE: The output of ADComp.bat is a semi-colon delimited string, like:
JSI001;"CN=JSI001,OU=Domain Controllers,DC=JSIINC,DC=COM"
JSI009;"CN=JSI009,CN=Computers,DC=JSIINC,DC=COM"
ADComp.bat contains:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set qry=adfind -default -f "&(objectcategory=computer)" -ps 99999 -nodn -noctl
for /f "Tokens=*" %%c in ('%qry%^|Find /I "name: "') do (
 set work=%%c
 if "!work:~1,19!" EQU "distinguishedName: " set dn="!work:~20!"
 if "!work:~1,6!" EQU "name: " @echo !work:~7!;!dn!
)
endlocal



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