Active Directory Sites and Services Script

I am looking for a way to complete a inventory of all properties in Active Directory Sites and Services and Export to Excel

Essentially I want the following data

SiteName,  Subnet, Server, Name of Server and IP address - Some sites have more than 1 server, and more than 1 subnet.

Also would like to get Site-Link for appropriate Site, and partner. with replication cost and interval

I have windows 2003 and Windows 2008 domain controllers.
Don't appear to have AD DS Web

I found a dsquery command, but it doesn't appear to work

dsquery site -o rdn -limit 0 > c:\folder\all.sites.txt
for /F %A in (c:\folder\all.sites.txt) do For /F %X in (‘dsquery subnet -site %A -o rdn’) do echo %A,%X >> c:\folder\sites.subnets.csv
for /F %A in (c:\folder\all.sites.txt) do For /F %X in (‘dsquery server -site %A -o rdn’) do echo %A,%X >> c:\folder\sites.Servers.csv
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.

Here is an example of what I think you need:

$Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
$obj = @()
foreach ($Site in $Sites) {

 $obj += New-Object -Type PSObject -Property (
   "SiteName"  = $site.Name
   "SubNets" = $site.Subnets -Join ";"
   "Servers" = $Site.Servers -Join ";"
$obj | Export-Csv 'sites.csv' -NoType

Open in new window

Reprinted from:

If you need help to modify let me know.
Life1430Sr EngineerCommented:
If you are intrested in good tool then here it is ...

Microsoft Active Directory Topology Diagrammer
This should do exactly what you need, simply plug in your text file value and go.

$sitelist = (gc sites.txt)
if (Test-path 'sites.csv')
{remove-item sites.csv -Force}
foreach ($site in $sitelist)
$Sites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | where {$_.Name -eq $site}
$obj = @()
foreach ($Site in $Sites) {
$Sitename = $ 
$Subnets = $site.subnets
$server = $Site.servers
foreach($subnet in $subnets)
$obj +=
$sitename, $server, $subnet
$obj | out-file 'sites.csv'  -Append

Open in new window


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
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
VB Script

From novice to tech pro — start learning today.