Hub Site Association
Summary
This sample shows how to associate sharepoint online site with hub site.
Implementation
- Open Windows PowerShell ISE
- Create a new file
- Write a script as below,
- First, we will connect to Tenant admin site.
- Then we read site url and hub site url from a user,
- And then we will do hub site association.
$AdminSiteURL = "https://{domain}-admin.sharepoint.com/"
$Username = "USERID"
$Password = "********"
$SecureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
Function Login() {
[cmdletbinding()]
param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $Creds)
Write-Host "Connecting to Tenant Admin Site '$($adminSiteURL)'" -f Yellow
Connect-PnPOnline -Url $adminSiteURL -Credentials $Creds
Write-Host "Connection Successful" -f Green
}
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 "Associate with a 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 hub site association:" $_.Exception.Message -ForegroundColor Red
}
}
Function StartProcessing {
Login($creds);
HubSiteAssociation
}
StartProcessing
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Chandani Prajapati (https://github.com/chandaniprajapati) |
Jasey Waegebaert |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.