This simple script enumerates all exchange servers in your active directory domain.
I will use this code again for a monitoring script (to be published later this week).
Follow the next steps to run the script (no admin rights needed):
- copy and paste the script in your favorite text editor
- save the script (for example c:templistexchangeserver.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript listexchangeserver.vbs” (without quotes) and enter
The script:
' Name : listexchangeserver.vbs
' Description : script to enumerate all exchange servers in your AD domain
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 06-04-2010
' Level: beginner
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("configurationnamingcontext") & ">"
strFilter = "(objectCategory=msExchExchangeServer)"
strAttributes = "name"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
Wscript.Echo adoRecordset.Fields("name").Value
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
When you have problems/questions please post a reply or give a ‘star’ rating.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
[adrotate group="2"]

[...] script is an extension of yesterday’s script. What the script [...]