Listing14_Links_For_Site (VBScript)

This code can be found in Chapter 9 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

'# From the book "Managing Enterprise Active Directory Services"
'# ISBN: 0-672-32125-4

Dim server, user, passwd, query_site, sites_dn, ist_dn
Dim filter, query, adoObj, resObj, count, name, cost

query_site = "RTP"

server = "dc1.xyz.com"
user   = "administrator@xyz.com"
passwd = "password"

' This could be dynamically retrieved using RootDSE
sites_dn = "cn=sites,cn=configuration,dc=xyz,dc=com"
ist_dn   = "cn=Inter-Site Transports," & sites_dn

filter = "(&(objectClass=siteLink)(objectCategory=SiteLink)" _
         & "(siteList=cn=" & query_site & "," & sites_dn & "))"
query = "<LDAP://" & server & "/" _
        &  ist_dn & ">;" & filter & ";name,cost;subtree"

' Set up the ADO query
Set adoObj = CreateObject("ADODB.Connection")
adoObj.Provider = "ADsDSOObject"
adoObj.Open "AD Provider", user, passwd
Set resObj  = adoObj.Execute(query)

count = 0
resObj.MoveFirst
While Not resObj.EOF
    count = count + 1
    name = resObj.Fields(0).Value
    cost = resObj.Fields(1).Value
    Wscript.Echo count & ". " & name & " (" & cost & ")"
    resObj.MoveNext
Wend

This code has been viewed 711 times.

New from the creators of TechTasks.com: StatSheet.com