Returning a list of all active directory sites

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.
LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

N-WCommented:
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
	Next
Next

objFile.close

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Thanks so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.