Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Enumerate ALL Servers in Domain

6 views
Skip to first unread message

Larry A Duncan

unread,
Feb 8, 2002, 2:17:27 PM2/8/02
to
Can anyone provide a sample VBScript to enumerate ALL servers in a specified
domain? I'm using the script below, but sadly it can't distinguish between a
member server and a workstation. I need to enumerate all DCs and Member
servers. This also has to happen with NOTHING MORE than ADSI and VBScript. I
can find 101 other ways to accomplish this, but I need it to be VBScript and
ADSI based. Period.

Anyone?

domain="yourdomain"
domain2="com"
On Error Resume Next
Set MyObject = GetObject("LDAP://OU=Domain Controllers,DC=" & domain &
",DC=" & domain2 )
if err<>0 then
if err<>-2147016656 then wscript.echo "unexpected error getting DCs"
else
On Error Goto 0
Set Container = MyObject
For Each Child in Container
Wscript.echo "DC: " & right( Child.Name, len(Child.Name)-3 )
Next
End If


Richard Mueller

unread,
Feb 8, 2002, 2:48:12 PM2/8/02
to
You could enumerate the members of the "Domain
Controllers" OU.

Set oDC = GetObject("LDAP://ou=Domain
Controllers,dc=MyDomain,dc=com")
For Each oServer In oDC
MsgBox oServer.Name
Next

I don't have any member servers, so I don't know where
they show up. If they are in cn=Computers, perhaps you can
find a property ("ObjectClass" or "MachineRole") in ADSI
Edit that can be used to indicate which computers are
member servers.

Richard

>.
>

Larry A Duncan

unread,
Feb 8, 2002, 3:09:26 PM2/8/02
to
That's what I'm already doing, which is clearly visible in the script I
provided. However, for the reasons stated, I need to include member servers.
The Computers OU only shows "Member Server or Workstation" in the machine
role.

Geesh! Is it really this difficult to enumerate all servers in the Active
Directory using ADSI?

"Richard Mueller" <RLMu...@ameritech.net> wrote in message
news:1d4801c1b0d9$8ac34790$35ef2ecf@TKMSFTNGXA11...

teac...@yahoo.com

unread,
Feb 10, 2002, 6:58:19 PM2/10/02
to
I think you could use the UserAccountControl attribute to determine this
..it may differ slightly for some..but should be relatively the same for the
domain roles.

patrick

"Larry A Duncan" <sms...@hotmail.com> wrote in message
news:#TzJpyNsBHA.1708@tkmsftngp03...

David Stucki [MS]

unread,
Feb 13, 2002, 7:45:43 PM2/13/02
to
To enumerate all DOMAIN CONTROLLERS in a domain do this:

' Get the Configuration Naming Context
Set oRootDSE = GetObject("LDAP://RootDSE")
strConfigNC = oRootDSE.Get("configurationNamingContext")

' Set up the oConnectionection
set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "ADs Provider"

' Build the query to find all Exchange ServeoRecordset
strQuery = "<LDAP://" & strConfigNC &
">;(objectClass=nTDSDSA);ADsPath;subtree"

set oCmd = CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConnection
oCmd.CommandText = strQuery
Set oRecordset = oCmd.Execute

' Iterate through the results
If oRecordset.Eof and oRecordSet.Bof Then
WScript.Echo "No Domain Controllers were found"
Else
While Not oRecordset.EOF
Set oParent = GetObject(GetObject(oRecordset.Fields("ADsPath")).Parent)
' Output the name of the server
WScript.Echo "Server: " & oParent.cn & " dNSHostName: " &
oParent.dNSHostName
oRecordset.MoveNext
Wend
End if


Dave Stucki
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.

Kevin Stanush

unread,
Feb 14, 2002, 2:09:38 AM2/14/02
to
I don't think that you can use Active Directory to list member
servers, but I could be wrong. I don't think that there is a setting
that identifies just servers vs. workstations.

My only suggestion is to use NetServerEnum, but this relies on the
Windows browse list.

Kevin Stanush
SystemTools Software Inc.
http://www.systemtools.com
Home of 'Hyena' for Windows NT/2000 System Administration

"Larry A Duncan" <sms...@hotmail.com> wrote in message news:<#TzJpyNsBHA.1708@tkmsftngp03>...

teac...@yahoo.com

unread,
Feb 16, 2002, 12:46:30 AM2/16/02
to
you can always fall back on WMI for the ones you are unsure of..of course
that assumes these are win2k machine or have WMI installed...

pat
"Kevin Stanush" <ke...@systemtools.com> wrote in message
news:8b0a3be0.02021...@posting.google.com...

0 new messages