lac.fi

Notes to self
› VBScript: List computers in domain

Finds all active computer objects under a root path. The PowerShell version does this with a fancier recursion.

Option Explicit
Dim objRoot, objContainer, objItem
Dim strList

strList = ""
Set objRoot = GetObject("LDAP://dc=domainname,dc=local")
DoContainer(objRoot)
MsgBox strList

Sub DoContainer(objContainer)
	For Each objItem in objContainer
		If objItem.class = "computer" Then
			If objItem.accountDisabled = False Then
				strList = strList & Mid(objItem.Name, 4) & vbCrLf
			End If
		End If
		If objItem.class = "organizationalUnit" Or objItem.class = "container" Then
			DoContainer(objItem)
		End If
	Next
End Sub