Copy left navigation from one subsite to other subsite
-
17-02-2021 - |
Question
I want to copy the quick launch from one subsite to other subsite using pnp powershell.
La solution
If the subsites are under the same parent site, here is a sample script for your reference:
#Connect to SPO site using PnP PowerShell
$SiteUrl = "https://<tenant>.sharepoint.com/sites/<ParentSite>"
$Username = "<Admin>"
$Password = "<Password>"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $(convertto-securestring $Password -asplaintext -force)
Connect-PnPOnline -Url $SiteUrl -Credential $cred
#Parameters
$SourceSub = "/sites/Team/sub1"
$TargetSub = "/sites/Team/sub2"
#Add Navigation Links
$n = Get-PnPNavigationNode -Web $SourceSub -Location QuickLaunch
Foreach($_ in $n){
Add-PnPNavigationNode -Web $TargetSub -Title $_.Title -Url $_.Url -Location QuickLaunch
}
Remember to use the relative URLs in the script.
It might return several errors since links like “Notebook” and “Site Contents” cannot be duplicated.
References: Get-PnPNavigationNode. / Add-PnPNavigationNode.
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange