Submitted By: Paul

Retrieves computer accounts from an OU and adds those accounts to a disconnected recordset.

Visual Basic
Edit|Remove
Const adVarChar = 200 
Const MaxCharacters = 255 

On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
Set DataList = CreateObject("ADODB.Recordset")

' Add field title
DataList.Fields.Append "ServerName", adVarChar, MaxCharacters
' Open dataset
DataList.Open

' Get domain name
strDomain = objRootDSE.Get("DefaultNamingContext")
' Create array with ous you wish to use
arrServer = Array("Domain Controllers")
' Loop through ous
For Each OU In arrServer
' Connect to individual ous
	Set objConfiguration = GetObject("LDAP://ou=" & OU & "," & strDomain)
' Filter on computers only
	objConfiguration.Filter = Array("computer")
' Loop through entities
	For Each objContainer in objConfiguration
' Add server to dataset
		DataList.AddNew 
		DataList("ServerName") = objContainer.CN
		DataList.Update 
	Next
Next

' Sort dataset
DataList.Sort = "ServerName" 
' Go to beginning of list
DataList.MoveFirst 

' Loop through dataset
Do Until DataList.EOF
	WScript.Echo DataList.Fields.Item("ServerName")
	DataList.MoveNext
Loop