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.
Source from an overview of the hub site.
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
  1. #SharePoint online site connection
  2. $Login = "[email protected]"
  3. $password = "********" #Enter your password
  4. $secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
  5. $Creds = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList $Login, $secureStringPwd
  6. Function HubSiteAssociation{
  7. try {
  8. #read site url from user
  9. $SiteUrl = Read-Host 'Enter Site Url'
  10. #read hub site URL from user
  11. $HubSiteUrl = Read-Host 'Enter Hub Site Url'
  12. Write-Host "Connecting to SharePoint site..." -ForegroundColor Yellow
  13. #connect to the SharePoint site
  14. Connect-PnpOnline -Url $SiteUrl -Credentials $Creds
  15. Write-Host "Association hub site..." -ForegroundColor Yellow
  16. #hub site association
  17. Add-PnPHubSiteAssociation -Site $SiteUrl -HubSite $HubSiteUrl
  18. Write-Host "Hub site association completed..." -ForegroundColor Yellow
  19. }
  20. catch {
  21. Write-Host "Error in adding hub site association:" $_.Exception.Message -ForegroundColor Red
  22. }
  23. }
  24. #call function
  25. HubSiteAssociation
Now run the script with the F5 command.
Output
Output - Hub site association

Summary

In this article, we have seen the association of the SharePoint site with the hub site.
I hope this helps.
Sharing is caring!