PowerShell to automatically create all AD hub-to-spoke site links
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,`
$Site.DistinguishedName;replInterval=15;cost=100 ;options=1}
# 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 # ><>
Comments
Anonymous
October 07, 2010
Neat. Welcome to the technical blogosphere Ashley.Anonymous
October 29, 2014
Welcome! Today’s post includes demo scripts and links from the Microsoft Virtual Academy event: Using PowerShell for Active Directory . We had a great time creating this for you, and I hope you will share it with anyone needing to ramp up their