WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Enumerating computers in a given Win2k AD Domain

Keywords: 	  Enumerating computers Win2k AD domain

Question:

Please help! I'm not a newbie to Winbatch however am a newbie to Windows 2000 / AD. All I need to do is just list all the computer names in a Windows 2000 domain regardless if the computers are in the default computers container or under other OUs.

I'll appreciate if someone can post a sample script please. Many thanks in advance.

Answer:

Here's how it is done using the ADSI extender.
;Load Appropriate Extender
If WinMetrics(-2) == 3 Then AddExtender("WWADS64I.DLL") ; 64-bit
Else AddExtender("WWADS44I.DLL") ; 32-bit

; Construct the full domain ADSI path.
ServerDn = dsGetProperty("LDAP://rootDSE", "serverName")
ServerName = ItemExtract(1, ServerDn, ",")
ServerName = ItemExtract(2, ServerName, "=")
ServerDn = dsGetProperty("LDAP://rootDSE", "defaultNamingContext")
ServerPath = "LDAP://%ServerName%/%ServerDN%"

; Find the computers path
ComputerPaths = dsFindPath(ServerPath, "(&(objectCategory=computer))")
AskItemlist('Compiter list', ComputerPaths, @TAB, @UNSORTED, @SINGLE )


Older example:

AddExtender("wwads34I.dll")

;  Set credentials
dsSetCredent("Buda", "********")

sAdsiPath = "LDAP://MyDomain" 

; Get all computers 
sSearch = "objectCategory=computer"   
lPaths= dsFindPath(sAdsiPath,  sSearch)

lCompNames = "" ; Need to initialize.
nCount = ItemCount(lPaths, @Tab)

for i=1 to nCount

   ; Get the common name.
   sPath = ItemExtract(i, lPaths, @Tab)
   sCompName = dsGetProperty(sPath, "cn")

   lCompNames = ItemInsert(sCompName,-1, lCompNames, @Tab)
next

; Display the results.
lCompNames = strreplace(lCompNames,@TAB, @CRLF)

Message("Computers", lCompNames)

Article ID:   W14510
Filename:   Enumerating computers in a Win2k AD domain.txt
File Created: 2012:11:15:09:20:16
Last Updated: 2012:11:15:09:20:16