SharePoint Hub Sites provide a way to organize related sites with shared navigation, branding, and governance. Using PnP PowerShell, administrators can automate the creation and management of hub sites, ensuring a structured and efficient SharePoint environment.
This guide covers:
Creating a Hub Site
Registering and Associating Sites
Managing Hub Site Navigation
Applying Policies and Permissions
Automating Hub Site Management
1. Connecting to SharePoint Online
Before managing hub sites, establish a connection to SharePoint Online.
Using Modern Authentication (MFA)
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -UseWebLogin
Using App Registration for Automation
$TenantID = "xxxx-xxxx-xxxx"
$ClientID = "yyyy-yyyy-yyyy"
$CertPath = "C:\Certificates\PnPCert.pfx"
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -ClientId $ClientID -Tenant $TenantID -CertificatePath $CertPath
Why? Ensures secure, automated access.
2. Creating a Hub Site
Convert an Existing Site to a Hub Site
Register-PnPHubSite -Site "https://yourtenant.sharepoint.com/sites/HubSite"
Why? This promotes a communication or team site to a hub site.
Create a New Site and Register as a Hub Site
1️⃣ Create a Modern Team Site
New-PnPSite -Type TeamSite -Title "Corporate Hub" -Url "https://yourtenant.sharepoint.com/sites/CorporateHub" -Alias "CorporateHub"
2️⃣ Register the New Site as a Hub Site
Register-PnPHubSite -Site "https://yourtenant.sharepoint.com/sites/CorporateHub"
Why? A structured hub improves navigation and governance.
3. Associating Sites with a Hub Site
Associate an Existing Site with a Hub Site
Add-PnPHubSiteAssociation -Site "https://yourtenant.sharepoint.com/sites/ProjectSite" -HubSite "https://yourtenant.sharepoint.com/sites/CorporateHub"
Why? Associates related sites under a common hub for streamlined navigation.
Associate Multiple Sites at Once
$Sites = @(
"https://yourtenant.sharepoint.com/sites/Finance",
"https://yourtenant.sharepoint.com/sites/Marketing",
"https://yourtenant.sharepoint.com/sites/HR"
)
foreach ($site in $Sites) {
Add-PnPHubSiteAssociation -Site $site -HubSite "https://yourtenant.sharepoint.com/sites/CorporateHub"
Write-Host "Associated $site with CorporateHub"
}
Why? Saves time by automating bulk associations.
4. Managing Hub Site Navigation
Add a Navigation Link to the Hub Site
Add-PnPNavigationNode -Title "HR Portal" -Url "https://yourtenant.sharepoint.com/sites/HR" -Location "QuickLaunch"
Why? Improves discoverability of key sites.
Remove a Navigation Link
Remove-PnPNavigationNode -Title "HR Portal" -Location "QuickLaunch"
Why? Helps keep the navigation clean and relevant.
5. Applying Hub Site Policies and Permissions
Assign a Hub Site Administrator
Set-PnPHubSite -Site "https://yourtenant.sharepoint.com/sites/CorporateHub" -Principals "admin@yourtenant.com"
Why? Ensures that only authorized users manage hub settings.
Enforce Site Join Approval for Associations
Set-PnPHubSite -Site "https://yourtenant.sharepoint.com/sites/CorporateHub" -RequireApproval $true
Why? Prevents unauthorized site associations.
6. Managing Hub Site Theme and Branding
Apply a Custom Theme to the Hub and Associated Sites
Set-PnPWebTheme -Theme "CorporateTheme" -WebUrl "https://yourtenant.sharepoint.com/sites/CorporateHub"
Why? Ensures a consistent brand experience.
7. Automating Hub Site Management
Automate Hub Site Creation and Association
$HubUrl = "https://yourtenant.sharepoint.com/sites/CorporateHub"
$NewSites = @(
"https://yourtenant.sharepoint.com/sites/IT",
"https://yourtenant.sharepoint.com/sites/Sales"
)
foreach ($site in $NewSites) {
New-PnPSite -Type TeamSite -Title "New Site" -Url $site -Alias "NewSite"
Add-PnPHubSiteAssociation -Site $site -HubSite $HubUrl
Write-Host "Created and associated $site with Corporate Hub"
}
Why? Speeds up site provisioning and governance.
8. Monitoring and Reporting on Hub Sites
Retrieve Hub Site Details
Get-PnPHubSite
Why? Provides an overview of all hub sites.
Get Associated Sites
Get-PnPHubSiteChild -Identity "https://yourtenant.sharepoint.com/sites/CorporateHub"
Why? Lists all sites associated with a specific hub.
Export Hub Site Information to CSV
$HubSites = Get-PnPHubSite
$HubSites | Export-Csv -Path "C:\Reports\HubSites.csv" -NoTypeInformation
Why? Useful for audits and governance tracking.
9. Unregistering and Removing Hub Sites
Dissociate a Site from a Hub
Remove-PnPHubSiteAssociation -Site "https://yourtenant.sharepoint.com/sites/ProjectSite"
Why? Useful when restructuring site collections.
Unregister a Hub Site
powershellCopyEditUnregister-PnPHubSite -Site "https://yourtenant.sharepoint.com/sites/CorporateHub"
✅ Why? Converts the hub site back to a regular site.
10. Best Practices for Managing Hub Sites
✅ Plan Site Architecture Before Creating Hub Sites
🔹 Define site categories (e.g., departments, projects).
✅ Use Secure Authentication for Automation
🔹 Always use App Registration or MFA for connections.
Enforce Governance for Site Associations
🔹 Require approval before sites join a hub.
Apply a Consistent Theme Across Hub Sites
🔹 Use Set-PnPWebTheme for unified branding.
Monitor Hub Site Usage
🔹 Regularly export hub site data for audits.