Copy-SPOHubSiteNavigation.ps1


<#PSScriptInfo
 
.VERSION 1.1
 
.GUID b8fc87fb-cb67-4968-977f-9b9d710ac21f
 
.AUTHOR NarasimaPerumal Chandramohan
 
.COMPANYNAME JiJi Technologies Private Limited
 
.COPYRIGHT All Right Reserved (c) JiJi Technologies Private Limited
 
.TAGS SPO Hubsites TopNavigation PowerShell
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES SharePointPnPPowerShellOnline
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>
 




<#
 
.DESCRIPTION
Using this script, you can copy the SharePoint Online Hub Site top navigation between sites.
 
 .PARAMETER SourceHubsiteUrl
 
Enter the Source SPO Hub site Url
 
.PARAMETER DestinationHubsiteUrl
 
Enter the Destination SPO Hub site Url
 
 
 
.EXAMPLE
Copy-SPOHubSiteNavigation.ps1 -SourceHubsiteUrl https://tenantname.sharepoint.com/sites/sourceHubsite -DestinationHubsiteUrl https://tenantname.sharepoint.com/sites/destHubsite
 
 
#>
 
Param(
[Parameter(ParameterSetName = "Inputparameter",Position=1,Mandatory=$True)]
[String]$SourceHubsiteUrl,
[Parameter(ParameterSetName = "Inputparameter",Position=2,Mandatory=$True)]
[String]$DestinationHubsiteUrl
)


Function Copy-NavigationToplink ($SourceHubsiteUrl,$DestinationHubsiteUrl,$Credentials)
{
    $GetTopNavs= Get-NavigationToplink -Hubsite $SourceHubsiteUrl -Credentials $Credentials
    Add-NavigationToplink -Topnavs $GetTopNavs -Hubsite $DestinationHubsiteUrl -Credentials $Credentials 
}

#Get Top Navigation from the given Hub Site
Function Get-NavigationToplink($Hubsite,$Credentials)
{
    Connect-PnPOnline -Url $Hubsite -Credentials $Credentials
    $TopNavs=Get-PnPNavigationNode -Location TopNavigationBar |Select Title,Url 
    Disconnect-PnPOnline
    return $TopNavs
}

#Add the Top Navigation to the given Hub Site
Function Add-NavigationToplink($TopNavs,$Hubsite,$Credentials)
{
    Connect-PnPOnline -Url $Hubsite -Credentials $Credentials
    foreach($TopNav in $TopNavs)
    {
     Add-PnPNavigationNode -Location TopNavigationBar -Title $TopNav.Title -Url $TopNav.Url
    }
}

$Credentials= Get-Credential 

Copy-NavigationToplink -SourceHubsiteUrl $SourceHubsiteUrl -DestinationHubsiteUrl $DestinationHubsiteUrl -Credentials $Credentials



# SIG # Begin signature block
# MIIVHwYJKoZIhvcNAQcCoIIVEDCCFQwCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUqv+37/OCQblftUma7+23ts0H
# HbmgghAPMIIEmTCCA4GgAwIBAgIPFojwOSVeY45pFDkH5jMLMA0GCSqGSIb3DQEB
# BQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQg
# TGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxITAfBgNV
# BAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdMBsGA1UEAxMUVVROLVVTRVJG
# aXJzdC1PYmplY3QwHhcNMTUxMjMxMDAwMDAwWhcNMTkwNzA5MTg0MDM2WjCBhDEL
# MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE
# BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKjAoBgNVBAMT
# IUNPTU9ETyBTSEEtMSBUaW1lIFN0YW1waW5nIFNpZ25lcjCCASIwDQYJKoZIhvcN
# AQEBBQADggEPADCCAQoCggEBAOnpPd/XNwjJHjiyUlNCbSLxscQGBGue/YJ0UEN9
# xqC7H075AnEmse9D2IOMSPznD5d6muuc3qajDjscRBh1jnilF2n+SR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