1

I need to delete all navigation from SharePoint site and subsites. please suggest any idea to do in powershell script.

2

Try below code:

$siteUrl = Get-SPSite "https://sitecollectionurl"

foreach ($spWeb in $siteUrl.AllWebs)
{  
    $nodeColl = $spWeb.Navigation.TopNavigationBar
    [int]$count=$nodeColl.Count                    
    while($count -ne 0)
    {  
       $nodeColl[$count-1].Delete();  
       $count--;
    }
}
$siteUrl.Dispose()
  • It shows error when entering Heading(or it contains child) . error is Cannot complete this action. Please try again. At C:\Users\Administrator\desktop\gokulbackups\NavExist.ps1:5 char:13 + foreach($node in ($spWeb.Navigation.TopNavigationBar)) + ~~~~~ + CategoryInfo : OperationStopped: (:) [], SPException + FullyQualifiedErrorId : Microsoft.SharePoint.SPException – PGP Feb 8 '17 at 12:34
  • Ahhh my bad, the foreach conundrum :( , try the edited code. – Gautam Sheth Feb 8 '17 at 12:40
  • Welcome macha :) – Gautam Sheth Feb 8 '17 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.