0

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

1

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()

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.