0

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
    clear
    $TermGroupName="Globale Navigation"
    $ParentTermSetName="Navigation"
    $WebApplication="http://srvsharepoint01/"

    $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
          } 
          else
          {
            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)
          }
          Else
          {
            write-host "Term Already Exists:"$sourceterm.name
          }
    }
    $store.CommitAll()
    $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
    $navSettings.Update()
    write-host "Updated Navigation for "$sitename
    $web.Dispose()
    }
    }

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.