Associate site automatically to a SharePoint Hub site

SharePoint Hub Sites new feature published on March 8, 2018, step by step to create Hub Site refer here. We have successfully created a hub site and associated with the sites. Now I am going to explain how to join/associate the hub site while creating new Team or Communication site.

In this article, I am going to explain how to associate site with site design automatically to a SharePoint Hub Site

Limit visibility of Site Design (scripts) based on scripts

  • We can able to associate automatically based on permissions settings, always think about the permission while planning.

Apply a site Design/Site Scripts When a site is being associate to the hub site

  • Site Design is nothing but previous Site template, for modern office 365 experience it is named as Site Design and create using PowerShell and JSON Scripts.
  • To apply a Hub Site to the site we need  to create a Hub Site.
  • To create Hub Site refer here

Register-SPOHubSite -Site https://jenkins.sharepoint.com/sites/SPHubSite

Go to Hub Site and open it,  Now you can see the global navigation header in the top of my hub site.

We have the Hub Site, Now we are going to join the Hub Site to Site Design (it is like a stapling feature

Step 1: Site ID : 8c19ff7b-9c27-4aff-b323-2631fc025271

  • Apply a Site Design we need Hub Site GUID
  • To get the Hub Site ID

Get-SPOHubsite url

Get-SPOHubsite https://jenkins.sharepoint.com/sites/SPHubSite

Step 2: JSON file

  • Required to create a JSON file, for this example I have created “sitescripts.json” and saved in my local drive

{
 "$schema": "schema.json",
 "actions": [
 {
 "verb": "joinHubSite",
 "hubSiteId": "8c19ff7b-9c27-4aff-b323-2631fc025271"
 }
 ],
 "bindata": { },
 "version": 1
}

Step 3: Power Shell Script

  • First Add SPOSitescript to Office 365

Get-Content 'D:\JPOWER4\SPHubSites\SiteScript.json'-Raw | Add-SPOSiteScript -Title "Jenkins Intranet Hub"

Adding SPOSite Scripts using PowerShell scripts

Step 4: Add the Site Design to SharePoint.aspx

AddSPOSiteDesign

Title :  Give the meaning full title name to identify the site design

WebTemplate – 64 stands for a Modern Team site.
WebTemplate – 68 stands for a Modern Communication site.

SiteScripts: Get the id from JSON site scripts added

Using this JSON file and PowerShell scripts, I have creates a Site Design named “SPHubSite Associated Site Design” to use with Office 365.


Add-SPOSiteDesign -Title "SPHubSite Associated Site Design" -WebTemplate "64" -SiteScripts "8152ef72-d2e1-412e-9031-61f9ad5de3eb" -Description "Creates a site using my SPHubSite"-PreviewImageUrl "https://jenkins.sharepoint.com/SiteAssets/hubsite.png" -PreviewImageAltText "site preview"

Now I have created a site design with Hub Site associated. To verify and test the site design, go to root site collection sharepoint.aspx page. In this example I have created a Team site SiteDesign. Let see the result while creating the site associated with the SPHubSite.

The Site design listed under the Team Site, Here I am going to create a Site using “SPHubSite Associated Site Design” template.

I have created “SitewithHub” Site using our new Site Design Template.you can able to select the privacy settings and give description also.

Click Next and add additional Owners and members for this site

Click Finish and Create the site.

It will create a site associated with the Hub site. Let see the output.

We successful created the Site with associated Hub.

Note:

  • Anytime you can change the Hub association with another hub or None.
  • But you can’t change the Theme with hub associated. It is always use the hub theme only.

I hope you found this helpful, If you need more help comment below…