In this blog, we are going to discuss about how to create Hub site, associate a site to it, get the associated site and remove the associated site using PowerShell.
What is Hub Site?
Hub sites bring the related sites together to roll up news, events & to simplify the search with shared navigation across the sites. These sites are meant to fulfil all the organisational need depending upon the projects and departments etc. A hub site can have team sites and communication sites associated to it. You can easily set related sites with shared look and feel, shared global navigation, scoped search and news and activates.
Follow the below steps to perform hub site operations using PnP PowerShell.
- Register a site as Hub.
- Associate a site to Hub Site.
- Get Associated Site of Hub site
- Remove Associated site
Register a site as Hub
Follow the below code to register a site as hub
- $siteURL=Read-Host“Enter the site Url”
- #Enter user name and password
- $credential=Get-Credential
- #connect pnp online
- Connect-PnPOnline-Url$siteURl-Credentials$credential
- #register associate site to hub site
- Register-PnPHubSite-Site$siteURL
In the parameter of “siteURL”, Enter that site URL which you want to register as Hub.
A Credential pop up will open as shown below. Enter your SharePoint username and password.

Before running the script,

After Running the script,

Associate a site to Hub Site
Follow the below powershell code to associate a site to hubsite.
- $tenantURL=Read-Host“Enter Tenant url”
- $hubURL=Read-Host“Enter Hubsite Url”
- $siteURL=Read-Host“Please provide site Url”
- #enter the user name and password
- $credential=Get-Credential
- #connect-Pnp Online
- Connect-PnPOnline-Url$tenantURL-Credentials$credential
- #add associated site to a hubsite
- Add-PnPHubSiteAssociation-Site$siteURL-HubSite$hubURL
In the parameter of “tenantURl”,enter your admin url like https://cottoso-admin.sharepoint.com.
In “hubURL” parameter, enter your hub site url in which you want to associate a site.
In “siteURL”, provide the site url that you want to associate to hub site.
Before running the script






Join the conversation! Your thoughts help the community grow.