1

I need to do scripts to set navigation for my publish sharepoint Online using CSOM PowerShell: Navigation Settings mean the same as Native Navigation Settings:

Global Navigation:(chose the top-level site,Managed Navigation and Structural Navigation)
Current Navigation:(chose the top-level site,Managed Navigation, Structural Navigation and Structural Navigation: Display only the navigation items below the current site)

and the same as Managed Navigation: Term Set

with c# I use this logic

    webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.PortalProvider;
webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.Unknown;
webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.Unknown;



pubWeb.Navigation.CurrentIncludeSubSites = false;
pubWeb.Navigation.CurrentIncludePages = false;
pubWeb.Navigation.CurrentDynamicChildLimit = 20;

but with powershell seems to be not the same. Any one know how?

3

You need to include the SharePoint.Client.Publishing.Navigation

You can change the values of the navigation source as per your requirement.

See below screenshot:

enter image description here

Try the below code in powershell:

#Credentials to connect to office 365 site collection url 
$url ="https://tenant.sharepoint.com/sites/home"
$username="user@tenant.onmicrosoft.com"
$password="yourpassword"
$Password = $password |ConvertTo-SecureString -AsPlainText -force

Write-Host "Load CSOM libraries" -foregroundcolor black -backgroundcolor yellow
Set-Location $PSScriptRoot
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Taxonomy.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Publishing.dll")

Write-Host "CSOM libraries loaded successfully" -foregroundcolor black -backgroundcolor Green 

Write-Host "authenticate to SharePoint Online Tenant site $url and get ClientContext object" -foregroundcolor black -backgroundcolor yellow  
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($url) 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) 
$Context.Credentials = $credentials 
$context.RequestTimeOut = 5000 * 60 * 10;
$web = $context.Web
$site = $context.Site 
$context.Load($web)
$context.Load($site)
try
{
  $context.ExecuteQuery()
  Write-Host "authenticateed to SharePoint Online Tenant site $url and get ClientContext object succeefully" -foregroundcolor black -backgroundcolor Green
}
catch
{
  Write-Host "Not able to authenticateed to SharePoint Online $_.Exception.Message" -foregroundcolor black -backgroundcolor Red
  return
}

#set both current and global navigation settings to structural
Write-Host "set both current and global navigation settings to structural started" -foregroundcolor black -backgroundcolor yellow
$taxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($context)
$navigationSettings = New-Object Microsoft.SharePoint.Client.Publishing.Navigation.WebNavigationSettings $context, $context.Web

#set both current and global navigation settings to structural
$navigationSettings.CurrentNavigation.Source = "portalProvider"
$navigationSettings.GlobalNavigation.Source = "portalProvider"

#For Display the same navigation items as the parent site
#$navigationSettings.CurrentNavigation.Source = "inheritFromParentWeb"
#$navigationSettings.GlobalNavigation.Source = "inheritFromParentWeb"

#For Managed Navigation
#$navigationSettings.CurrentNavigation.Source = "taxonomyProvider"
#$navigationSettings.GlobalNavigation.Source = "taxonomyProvider"

$navigationSettings.Update($taxonomySession)

try
{
$Context.ExecuteQuery()
Write-Host "setting both current and global navigation settings to structural Completed" -foregroundcolor black -backgroundcolor green
}
catch
{
Write-Host "Error while setting both current and global navigation settings to structural" $_.Exception.Message -foregroundcolor black -backgroundcolor Red
}


// disable quick launch navigation including subsites and pages    
$context.Load($web.AllProperties)
$Context.ExecuteQuery()
$web.AllProperties["__IncludeSubSitesInNavigation"] = "False"
$web.Update()
$Context.ExecuteQuery()

$web.AllProperties["__IncludePagesInNavigation"] = "False"
$web.Update()
$Context.ExecuteQuery()

#set dynamic child limit for current navigation
$web.AllProperties["__CurrentDynamicChildLimit"] = 20
$web.Update()
$Context.ExecuteQuery()

#set dynamic child limit for global navigation
#$web.AllProperties["__GlobalDynamicChildLimit"] = 20
#$web.Update()
#$Context.ExecuteQuery()
  • thanks, Gautam .works fine for CurrentNavigation.Source but for $props.FieldValues doesnt work ! any idea – Imen Turki Dec 19 '16 at 11:28
  • can you check now ? i forgot to load property bag value. Have updated the code. – Gautam Sheth Dec 19 '16 at 11:44
  • could not found __IncludeSubSitesInNavigation and __IncludePagesInNavigation – Imen Turki Dec 19 '16 at 12:39
  • 1
    check now. have edited how we update property bag value – Gautam Sheth Dec 19 '16 at 13:18
  • Big thanks Gautam now it works fine , you save my life Man :) – Imen Turki Dec 19 '16 at 14:10

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.