Re: How to determine server role
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 03/11/05
- Next message: de Graff: "Scan an image to fit"
- Previous message: Torgeir Bakken \(MVP\): "Re: INI Files"
- In reply to: Wensi Peng: "How to determine server role"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: de Graff: "Scan an image to fit"
- Previous message: Torgeir Bakken \(MVP\): "Re: INI Files"
- In reply to: Wensi Peng: "How to determine server role"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|