List all computers in Domain


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
'     Run this script via cscipt other wise edit to direct output to text file
'     ListComputers.vbs

Dim RootDSE, DomainNC, Connection, Command, RecordSet

' CALLOUT A
Set RootDSE = GetObject("LDAP://rootDSE")
DomainNC = RootDSE.Get("defaultNamingContext")
' 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://" & DomainNC _
  & ">;(objectCategory=Computer);CN;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
  WScript.Echo RecordSet.Fields("CN").Value
  RecordSet.MoveNext()
Loop
' END CALLOUT C

Connection.Close()



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


Further Reading
    None Found




One Response to “List all computers in Domain”

  1. Automoto1 says:

    Ridiculous quest there. What occurred after? Thanks!

Leave a Reply

Anti-Spam Quiz:

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