Introduction
Hub Site is a collection of sites connected to a master site from where all connected sites can be navigated and managed.
Features
Discover related content such as news and other site activities, Apply common navigation, branding, and site structure across associated sites. Search across all associated sites.
For more details, refer to
this article.
Implementation
Step 1
Open Windows Powershell ISE
Step 2
Create a new file
Step 3
Write a script as below,
In the script, we will take two inputs from the user
Site Url - the site which we want to associate with the hub site
Hub site Url - the site URL, with we want to associate our site
- #SharePoint online site connection
- $Login = "[email protected]"
- $password = "********" #Enter your password
- $secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
- $Creds = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList $Login, $secureStringPwd
-
- Function HubSiteAssociation{
- try {
- #read site url from user
- $SiteUrl = Read-Host 'Enter Site Url'
-
- #read hub site URL from user
- $HubSiteUrl = Read-Host 'Enter Hub Site Url'
-
- Write-Host "Connecting to SharePoint site..." -ForegroundColor Yellow
-
- #connect to the SharePoint site
- Connect-PnpOnline -Url $SiteUrl -Credentials $Creds
-
- Write-Host "Association hub site..." -ForegroundColor Yellow
-
- #hub site association
- Add-PnPHubSiteAssociation -Site $SiteUrl -HubSite $HubSiteUrl
-
- Write-Host "Hub site association completed..." -ForegroundColor Yellow
- }
- catch {
- Write-Host "Error in adding hub site association:" $_.Exception.Message -ForegroundColor Red
- }
- }
-
- #call function
- HubSiteAssociation
Now run the script with the F5 command.
Output
Summary
In this article, we have seen the association of the SharePoint site with the hub site.
I hope this helps.
Sharing is caring!