I'm using the following code to have a global navigation across all my site collections via the managed metadata service.

Add-PSSnapin microsoft.sharepoint.powershell
    $TermGroupName="Globale Navigation"

    $WebApp = get-spwebapplication $webapplication
    foreach ($site in $webapp.sites) 
        if ($site.ServerRelativeUrl -ne "/") 
            $siteName = $site.ServerRelativeUrl.ToString()
            $siteName = $sitename.trim("/")
            $termGroup = $TermGroupName
            $ParentTermSet = $ParentTermSetName
            $dstTermSetName = "[AutoGeneratedViaPS] Global Navigation - " + $siteName 
            $web = get-spweb $site.url
            $session = Get-SPTaxonomySession -site $site 
            $store = $session.DefaultKeywordsTermStore
            $group = $store.groups[$termgroup]
            $srctermset = $group.termsets[$ParentTermSet]
            $dstTermSet = $null
            $dstTermSet = $group.TermSets | ? {$_.name -eq $dstTermSetName}
         if ($dstTermSet -eq $null)
            write-host "Creating Term Set:"$dstTermSetName
            $dsttermset = $group.CreateTermSet($dstTermSetName)
            $dsttermset.SetCustomProperty("_Sys_Nav_IsNavigationTermSet", "True")
            $dsttermset.CustomSortOrder = $srctermset.CustomSortOrder
            write-host "Term Set Already Exists:"$dstTermSetName
          foreach ($sourceTerm in $srctermset.terms)
            $newterm = $null
            $newterm = $dsttermset.terms | ? {$_.name -eq $sourceterm.name}
          If ($newterm -eq $null)
            write-host "Adding Term:"$sourceterm.name
            $newterm = $dsttermset.reusetermwithpinning($sourceTerm)
            write-host "Term Already Exists:"$sourceterm.name
    $navSettings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($web)
    $navSettings.GlobalNavigation.Source = 2
    $navSettings.GlobalNavigation.TermStoreId = $Store.Id
    $navSettings.GlobalNavigation.TermSetId = $dsttermset.Id
    $navSettings.AddNewPagesToNavigation = $false
    $navSettings.CreateFriendlyUrlsForNewPages = $false
    write-host "Updated Navigation for "$sitename

My goal is to now have exactly one link different and unique for each site collection while all other links should be like defined in $ParentTermSetName.

So within the Termsets "[AutoGeneratedViaPS] Global Navigation - " + $siteName I wan't one term to have a specific unique URL.

Is there any way I can do this via the above powershell script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.