Skip navigation

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

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 Explicit
Dim objConnection, objChild
Set objConnection =
  objConnection.Filter = Array("trustedDomain")
For Each objChild In objConnection
  WScript.Echo objChild.Name
Wscript.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, the line would read:

Set objConnection =

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.