Geeks With Blogs
Points To Share Mostly SharePoint

At times I create so many sites and sub-sites that the Top-Nav cannot handle it. It is better to add the new links to the Quick Launch.

The function below makes it a snap.

Here is how it is used:

The first line inserts a heading "OrgSites" under the "Lists" heading (already there) in the QuickLaunch.

New-SPNode -Web $siteurl -NodeText "OrgSites" -NodeLink "Head" -NodeParent "Lists"

TAnd this line inserts the URL of a site named $web1name and the URL $web1url unter the new "OrgSites" heading

New-SPNode -Web $siteurl -NodeText $web1name -NodeLink $web1url -NodeParent "OrgSites"

Here (FINALLY!!) is the function

# New-SPNode creates an entry in the QuickLaunch navigation
# $Web is the URL of the site
# A node is made of text - $NodeText and link - $NodeLink
# If the link says "Head", then the node is a heading, else it is assumed a URL
# If "Head" then the heading is added immediately under The parent heading ($NodeParent)
# No checking for a URL being a URL
# Nodes are always added last
# Nodes are added under $NodeParent

function New-SPNode {
    [CmdletBinding()]
   
Param(
    [Parameter(Mandatory
=$true,ValueFromPipeline=$true)]
    [
string]$Web,
    [Parameter(Mandatory
=$true)]
    [
string]$NodeText, #"Head" if Heading
    [Parameter(Mandatory
=$true)]
    [
string]$NodeLink,
    [Parameter(Mandatory
=$true)]
    [
string]$NodeParent
    )
Start-SPAssignment -Global
$SPWeb
= Get-SPWeb -Identity $Web
$QL
= $SPWeb.Navigation.QuickLaunch # QuickLaunch
$PrevHead
= $QL | where {$_.Title -eq $NodeParent}
# Check if heading
If
($NodeLink -eq "Head")
{
     
$NewHead = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($NodeText, "")      $QL.Add($NewHead, $PrevHead) | Out-Null

}
else

{

     
$NewNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($NodeText, $NodeLink)

      Write-Host "New-SPNode: " $Web " " $NodeText " " $NodeParent -ForegroundColor Blue -Backgroundcolor magenta
     
$PrevHead.Children.AddAsLast($NewNode) | Out-Null
}
$SPWeb
.Dispose()
Stop-SPAssignment -Global

}

That's All Folks!!
Posted on Sunday, May 19, 2013 12:44 PM SharePoint , PowerShell , QuickLaunch | Back to top


Comments on this post: SharePoint QuicLaunch Maker with PowerShell

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © PointsToShare | Powered by: GeeksWithBlogs.net