Вопрос

I want to change navigation in my website with powershell

This is my code:

function SettingUpNavigation($webURL){
    $spWeb = Get-SPWeb -Identity $webURL 

    $SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)

    $SPPubWeb.Navigation.InheritGlobal = $false
    $SPPubWeb.Navigation.GlobalIncludeSubSites = $true
    $SPPubWeb.Navigation.GlobalIncludePages = $false
    $SPPubWeb.Navigation.GlobalDynamicChildLimit = 20

    $SPPubWeb.Navigation.InheritCurrent = $false
    $SPPubWeb.Navigation.ShowSiblings = $false
    $SPPubWeb.Navigation.CurrentIncludeSubSites = $true
    $SPPubWeb.Navigation.CurrentIncludePages = $false
    $SPPubWeb.Navigation.CurrentDynamicChildLimit = 20

    $SPPubWeb.Update();

    $spWeb.Dispose()
}

I want this:

1) enter image description here

2) enter image description here

Это было полезно?

Решение

I think you want to make sure global and current navigation are set to use structural navigation.

For that, you can use the below PowerShell script:

$spWeb = Get-SPWeb -Identity $webURL

#setting global and current navigation source
$navSetting=new-object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($spWeb)
$navSetting.GlobalNavigation.Source=[Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
$navSetting.CurrentNavigation.Source=[Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
$navSetting.Update()

#global navigation setting
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$SPPubWeb.Navigation.InheritGlobal = $false
$SPPubWeb.Navigation.GlobalIncludeSubSites = $true
$SPPubWeb.Navigation.GlobalIncludePages = $false
$SPPubWeb.Navigation.GlobalDynamicChildLimit = 20

#current navigation setting
$SPPubWeb.Navigation.InheritCurrent = $false    
$SPPubWeb.Navigation.ShowSiblings = $false
$SPPubWeb.Navigation.CurrentIncludeSubSites = $false
$SPPubWeb.Navigation.CurrentIncludePages = $false
$SPPubWeb.Navigation.CurrentDynamicChildLimit = 20

$SPPubWeb.Update()

#show/hide ribbon setting
$spWeb.AllProperties["__DisplayShowHideRibbonActionId"] = $false.ToString()
$spWeb.Update() 

$SPPubWeb.Dispose()
$spWeb.Dispose()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top