How can I use a script to create a list of domains that an Active Directory (AD) domain trusts?

John Savill

April 13, 2005

1 Min Read
ITPro Today logo

A. Using the Active Directory Services Interface (ADSI) you can use a script like the following sample to query objects from AD--such as trustedDomain objects from a domain's system container--and thereby obtain a list of all the trusted domains.

Option ExplicitDim objConnection, objChildSet objConnection =GetObject("LDAP://vs2003dstdc1.dest.test/cn=system,dc=dest,dc=test")  objConnection.Filter = Array("trustedDomain")For Each objChild In objConnection  WScript.Echo objChild.NameNextWscript.Echo "Operation Completed"

Ensure that you replace the "Set objConnection" Lightweight Directory Access Protocol (LDAP) connection string with one for your domain. For example, if a domain controller (DC) is DC1 in domain savilltech.com, the line would read:

Set objConnection =GetObject("LDAP://dc1.savilltech.com/cn=system,dc=savilltech,dc=com")

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like