Home > Navigation, Powershell, SharePoint, SharePoint 2010, SharePoint Server 2010 > Site Settings by PowerShell part 1.1 Delete navigation nodes

Site Settings by PowerShell part 1.1 Delete navigation nodes

February 14, 2012 Leave a comment Go to comments

This time I will give you a sample script that will enumerate all of your subwebs and remove a node from the current navigation.
A very useful script if you have a large and complec site structure and when you want to change the global or current navigation.

In my example, I am enumerating all subwebs of my sitecollection, and in the current navigation of every subweb, I remove the ‘Ste Pages’ link that you get from enabling publishing. If you want to remove a different link, find the ID of that link and replace or add a $currentnode… to the script.

Since my users have no use for the ‘site pages’ link, I’ll simply remove it from navigation.

# get a sitecollection object(SPSite) 
$SPSite = Get-SPSite -Identity “http://farm.company.local/sitecollection“ 
# loop through all the subwebs(SPWebs) in the site collection 
foreach ($SPWeb in $SPSite.AllWebs) 
{   
# Get a navigation node object and delete it   
$currentnode = $SPWeb.Navigation.GetNodeByID(2001)   
$currentnode.Delete()   
# Make it stick...   
$SPWeb.Update()   
Write-Host “Removing the Node: ” $currentNode.URL 
}

A comlex way of finding out a nodes ID, is to do as follows:

$SPWeb = Get-SPWeb "http://farm.company.local/sitecollection/Web"

(Check in site settings/Navigation what the url for the node is, for example:)

$currentnode = $web.Navigation.GetNodeByUrl 
("site/Web/SharedDocuments/Forms/AllItems.aspx") 
$currentnode.ID

That will probably give you the ID 2002 for ‘Shared Documents’

Thats it!

Good luck.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: