Goatee PFE

Blog of Microsoft Premier Field Engineer Ashley McGlone featuring PowerShell scripts for Active Directory.

PowerShell to automatically create all AD hub-to-spoke site links

PowerShell to automatically create all AD hub-to-spoke site links

  • Comments 2
  • Likes

So you've just finished creating all of the sites in your AD forest, or you've chosen to rebuild your site link topology.  You want to create a simple hub-and-spoke site link topology.  You dread all the clicks it will take to create each site link, type the name, and add the member sites.  Enter today's script.

Now you can create all of your site links with this PowerShell script.  Simply change the variable holding the name of the hub site (HubSiteNameHere) to the hub site in your design.  The script does the rest.  It will create each site link and add the member sites to it.

Now you can go back to counting ceiling tiles.  Enjoy.

PS - Change this one part of the script to enable change notification on each site link:
-OtherAttributes @{siteList=$SiteHub.DistinguishedName,`

# Active Directory Site Link Creator           
# Ashley McGlone, Microsoft PFE, 10/6/2010           
# PowerShell script to create hub-to-spoke site links and populate them           
# with the two site members.  This script requires that all sites be           
# created already. This script assumes that all sites will be connected           
# directly to a single hub.  Can be run again with a different hub site           
# name to create redundant site links to a second hub site.           
# INSTRUCTIONS:           
# Adjust this variable to hold the site name of the hub site:           
#     $SiteHubName = "HubSiteNameHere"           
# Run the script.           
Import-Module ActiveDirectory           
$ConfigPath = (Get-ADRootDSE).configurationNamingContext           
$SiteLinkPath = "CN=IP,CN=Inter-Site Transports,CN=Sites," + $ConfigPath           
#Get the hub site           
$SiteHubName = "HubSiteNameHere"           
$SiteHub = Get-ADObject `
    -Filter 'ObjectClass -eq "site" -and CN -eq $SiteHubName' `
    -SearchBase $ConfigPath           
#Get all other sites           
$SiteAll = Get-ADObject `
    -Filter 'ObjectClass -eq "site" -and CN -ne $SiteHubName' `
    -SearchBase $ConfigPath           
#For each site           
ForEach ($Site in $SiteAll) {           
    #Create a site link of name Hub-Spoke, Interval of 15 minutes,           
    # Cost of 100, Site link members being the hub and spoke sites           
    $SiteLinkName = $SiteHub.Name + " - " + $Site.Name           
    New-ADObject -name $SiteLinkName -type siteLink -path $SiteLinkPath `
        -OtherAttributes @{siteList=$SiteHub.DistinguishedName,$Site.DistinguishedName;replInterval=15;cost=100}           
Get-ADObject -Filter 'ObjectClass -eq "siteLink"' -SearchBase $ConfigPath `
    -Properties * | Format-Table Name, replInterval, cost, siteList -AutoSize           
#   ><>           




Attachment: sitelinks.txt

Can you help me?  Yes!

If you would like to have me or another Microsoft PFE visit your company and assist with the ideas presented in this blog post, then contact your Microsoft Premier Technical Account Manager (TAM) for booking information.

For more information about becoming a Microsoft Premier customer email PremSale@microsoft.com.  Tell them GoateePFE sent you.

Sharing Links
  • Neat. Welcome to the technical blogosphere Ashley.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment