Modify QuickLaunch of SharePoint web with Powershell

I had to modify the quicklauch for multiple webs. In this case Powershell is my friend. The action needed to be done was to show subwebs in QuickLaunch. If publishing feature is activated on web, this property can be set on /_layouts/AreaNavigationSettings.aspx.

AreaNavigationSettings

With Powershell the property is a bit tricky to find. First, web need to create a PublishingWeb-object.

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

Second, the CurrentIncludeSubSites property of the Navigation property must be set to true.

$pubWeb.Navigation.CurrentIncludeSubSites = $true

The complete function looks something like this.


param(
[parameter(Mandatory = $true)][string]$Url
)

function Set-CurrentIncludeSubSites()
{
#Load assemblies
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$web = Get-SPWeb $Url

if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) -eq $true)
{
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pubWeb.Navigation.CurrentIncludeSubSites = $true
$pubWeb.Update()
}
}

Set-CurrentIncludeSubSites -Url $Url

Save this as Set-CurrentIncludeSubSites.ps1 and run it with .\Set-CurrentIncludeSubSites.ps1 -Url http://myurl

Leave a Reply

Your email address will not be published. Required fields are marked *