Friday, February 20, 2009

List domains in a forest using script

The following code displays the domains contained in a forest.

1. Assume the foresst root is "microsoft.com"

strForestRoot = "microsoft.com" ' i.e., dc=microsoft, dc=com
strADsPath = ";"
strFilter = "(netbiosname=*);"
strAttrs = "dnsRoot;"
strScope = "SubTree"
set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objRS = objConn.Execute(strADsPath & strFilter & strAttrs & strScope)
objRS.MoveFirst while Not objRS.EOF
For Each root in objRS.Fields("dnsRoot").Value
WScript.Echo(root)
Next objRS.MoveNext
wend

0 comments:

Design by infinityskins.blogspot