Returning a list of all active directory sites

Posted on 2013-09-15
Medium Priority
Last Modified: 2013-10-08
Dear everyone,
I hope this finds you all well and can assist :>)

We are looking t:

1) extracting a list of all active directory site names along with their
2) site descriptions
3) domain controllers for each site

Something like the following:

-------------------------------------- sites.csv
<site>, <siteDescription>, <domainControllerName>
siteA, Tokyo, jpdc

Any help greatly appreciated.
Question by:Simon336697

Accepted Solution

N-W earned 2000 total points
ID: 39495036
This VBScript should do what you want:
Option Explicit

Dim objFSO, objFile, objRootDSE, objSitesContainer, objSite, objServer
Dim strConfigurationNC, strSitesContainer, strSiteName, strSiteDescription, strServerPath
Dim colServers
Const strFilePath = "C:\ADSitesServers.csv"

Set objFSO = Createobject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, 2, True)
objFile.WriteLine "Site Name,Site Description,DC Name"

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
	strSiteName = objSite.Name
	strSiteDescription = objSite.Description
	strServerPath = "LDAP://cn=Servers," & strSiteName & ",cn=Sites," & strConfigurationNC
	Set colServers = GetObject(strServerPath)
	For Each objServer In colServers
		objFile.WriteLine objSite.CN & "," & strSiteDescription & "," & objServer.CN


Open in new window

Modify the constant on line 6 which contains the path of the output file to where you want it to save. Then save the file with a .vbs extension and run it.

Author Closing Comment

ID: 39555151
Thanks so much.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Seizing the Operation Master Roles in Windows Server 2016 in case of FSMO holder failure.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question