Site Settings by PowerShell part 1.1 Delete navigation nodes

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 ““ 
# 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)   
# Make it stick...   
Write-Host “Removing the Node: ” $currentNode.URL 

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

$SPWeb = Get-SPWeb ""

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

$currentnode = $web.Navigation.GetNodeByUrl 

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

Thats it!

Good luck.


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s