Top Menu

Tuesday, October 14, 2014

SharePoint 2007 - Delete Global Navigation using PowerShell

Scenario:
Recently support team at my client found out that for some reason too many links (more than 1000) got created under a heading node in the Global Navigation in one of our SharePoint 2007 portals and it is making the whole site collection slow.

When I try to delete the group node from the UI, it gets deleted but the child nodes become the parent nodes. Funny....but not so funny when it is in production environment. So I wrote following the script in Powershell 2.0 for SharePoint 2007 to kill the parent node (and it will automatically delete all the child nodes under it).

Solution:
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Sharepoint”)

$siteURL = "https://sharepoint2007portal"
$spSite = new-object Microsoft.Sharepoint.SPSite($siteUrl)
$spWeb = $spSite.RootWeb

Foreach($node in ($spWeb.Navigation.TopNavigationBar))
{
    
    if ($node.Title -eq "MyHeading")
    {
        write-host "Node: " $node.Title

        //this will delete the node and its child
        $node.Delete() 

        write-host "Deleted successfully."
    }
    
}
$spWeb.Dispose() 

write-host "Done."

No comments:

Post a Comment

Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...