Re: How to determine server role

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 03/11/05


Date: Fri, 11 Mar 2005 23:13:40 +0100

Wensi Peng wrote:

> I have many servers in a win2003 domain. I would like to have
> a ADSI vbscript to determine the system role:
> like, Domain Controller, member server, further more WINS, DNS,
> DHCP roles even better.
Hi

Below is a script that first list all Domain Controllers, then
member servers that are found as computer objects in AD.

Run the script in a command prompt (cmd.exe), like this

cscript.exe "c:\some path\some file.vbs"

If you want to redirect the list to a file:

cscript.exe //Nologo "c:\some path\some file.vbs" >C:\ServerInfo.txt

'--------------------8<----------------------
Option Explicit

Dim objRootDSE, strDNSDomain, objCommand, objConnection, strBase
Dim strFilter, strQuery, objRecordSet, strNoDC, strOnlyDC
Dim strDN, strName, intCount

' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Start search from here
strBase = strDNSDomain

' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"

' Find Domain Controllers

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Sort On") = "Name"

strOnlyDC = "(userAccountControl:1.2.840.113556.1.4.803:=8192)"

strFilter = "(&(objectCategory=computer)(operatingSystem=*Server*)" _
     & strOnlyDC & ")"

strQuery = "<LDAP://" & strBase & ">;" & strFilter _
     & ";name,distinguishedName;subtree"

objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

WScript.Echo "Domain Controllers:"
' Loop through all found computer objects.
intCount = 0
Do Until objRecordSet.EOF
   intCount = intCount + 1
   strName = objRecordSet.Fields("Name").Value
   strDN = objRecordSet.Fields("distinguishedName").Value
   WScript.Echo strName & " " & strDN

   ' Move to the next computer object.
   objRecordSet.MoveNext
Loop

WScript.Echo "Count: " & intCount

' Find member servers

strNoDC = "(!userAccountControl:1.2.840.113556.1.4.803:=8192)"
strFilter = "(&(objectCategory=computer)(operatingSystem=*Server*)" _
           & strNoDC & ")"

strQuery = "<LDAP://" & strBase & ">;" & strFilter _
     & ";name,distinguishedName;subtree"

objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

WScript.Echo "Member servers:"
' Loop through all found computer objects.
intCount = 0
Do Until objRecordSet.EOF
   intCount = intCount + 1
   strName = objRecordSet.Fields("Name").Value
   strDN = objRecordSet.Fields("distinguishedName").Value
   WScript.Echo strName & " " & strDN

   ' Move to the next computer object.
   objRecordSet.MoveNext
Loop

objConnection.Close

WScript.Echo "Count: " & intCount

'--------------------8<----------------------

-- 
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Relevant Pages

  • Re: Collect Member Servers [WILDPACKET]
    ... > Below is a VBScript that lists all member servers. ... > ' Loop through all found computer objects. ... > torgeir, Microsoft MVP Scripting, Porsgrunn Norway ...
    (microsoft.public.windows.server.active_directory)
  • Windows 2000 Member servers behind a firewall
    ... a couple of member servers in a DMZ. ... >adequately protect the inside domain controllers from ... >** Port 5050 is a statically defined port for Active ... >Registry Modifications: ...
    (microsoft.public.win2000.security)
  • Re: Migration from win2000 to 2008
    ... After you have migrated all the objects from the source domain to the target domain, including all the computers and member servers, only the domain controllers remain in the source domain. ...
    (microsoft.public.windows.server.migration)
  • Re: Non domain admins installing software on domain controllers
    ... > of domain controllers and member servers distributed through out ... > object for administrators within each country and for member server we ... > domain controllers in that they cannot perform the action because they ... > install patches as and when they become available. ...
    (microsoft.public.win2000.security)
  • Re: Active Directory Functional Level
    ... > If I switch to 2000 or 2003 native mode will it break anything? ... several Windows NT4 member servers running, one of them with Exchange 5.5. ... functional level only applies to domain controllers. ...
    (microsoft.public.windows.server.active_directory)

Quantcast