Lists Domain Controllers


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'     Lists all domain controllers in domain
'
'     Run this via Cscript or direct output to text
'
'     ListDCs.vbs

Dim RootDSE, ConfigNC, Connection, Command, RecordSet, DC

' CALLOUT A
Set RootDSE = GetObject("LDAP://rootDSE")
ConfigNC = RootDSE.Get("configurationNamingContext")
' END CALLOUT A

Set Connection = CreateObject("ADODB.Connection")
Connection.Open("Provider=ADsDSOObject;")

Set Command = CreateObject("ADODB.Command")
Command.ActiveConnection = Connection

' CALLOUT B
Command.CommandText = "<ldap://" & ConfigNC _
  & ">;(objectClass=nTDSDSA);AdsPath;subtree"
' END CALLOUT B
Command.Properties("Cache Results") = False
Command.Properties("Page Size") = 100
Command.Properties("Sort On") = "CN"
Command.Properties("Timeout") = 30

Set RecordSet = Command.Execute()

' CALLOUT C
Do While Not RecordSet.EOF
  Set DC = GetObject(GetObject(RecordSet.Fields("AdsPath").Value).Parent)
  WScript.Echo DC.CN
  RecordSet.MoveNext()
Loop
' END CALLOUT C

Connection.Close()



You can leave a response, or trackback from your own site.


Further Reading
    None Found




Leave a Reply

Anti-Spam Quiz:

Twitter Delicious Facebook Digg Stumbleupon Favorites More
334 queries in 2.816 seconds.