How can I use a script to list sites in Active Directory (AD)?

A. The following script, which you can download here , outputs a list of AD sites:

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")

For Each objSite In objSitesContainer
    WScript.Echo "Site: " & Mid(objSite.Name,4)
Next
Here's a sample execution of the above code:
D:\Temp>cscript listsites.vbs
 
Site: Dallas
Site: London
Site: NewYork
Hide comments

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.
Publish