Skip to content

Instantly share code, notes, and snippets.

@devendrasv
Created September 7, 2014 21:59
Show Gist options
  • Save devendrasv/464ab5e0746b8211d7b4 to your computer and use it in GitHub Desktop.
Save devendrasv/464ab5e0746b8211d7b4 to your computer and use it in GitHub Desktop.
#Credentials to connect to office 365 site collection url
$url ="https://velegandla.sharepoint.com/sites/pubportal1"
$username="[email protected]"
$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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment