I'm using the following PowerShell script to update the Navigation.GlobalIncludeSubSites value from true to false, which is working, except that the changes are not properly applied.

By that I mean that if I look at the AreaNavigationSettings.aspx page for a site before I run the script I see that "Show subsites" is checked (and the page is showing the wrong menu). After I run the script below, and check that page again, the checkbox is unchecked, but the site is still showing the wrong menu. Only after I click OK on the AreaNavigationSetting.aspx page does the correct menu show up.

As you can see in my code, I am using $pubWeb.Update(), so I'm not sure why the changes aren't being applied without manually clicking OK on each AreaNavigationSettings.aspx page, which defeats the purpose of using the script in the first place.

function ProcessSubWebs($currentWeb)
   foreach($sub in $currentWeb.Webs)
      if($sub.Webs.Count -ge 0)
         Write-Host -ForegroundColor black $sub.Url

function UpdateNavigation($web)
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    Write-Host -ForegroundColor green $pubWeb.Navigation.GlobalIncludeSubSites
    $pubWeb.Navigation.InheritGlobal = $true
    $pubWeb.Navigation.GlobalIncludeSubSites = $false
    $pubWeb.Navigation.GlobalIncludePages = $false

ProcessSubWebs(Get-SPWeb -identity http://myserver/site1)
Write-Host -ForegroundColor red "FINISHED"

Any ideas?

[update based on Dave Wise's answer below]




$web.AllowUnsafeUpdates = 1;

worked for me! Thanks Dave :)

  • Are you using output caching?
    – Dave Wise
    Commented Feb 15, 2012 at 18:21
  • I don't even know what that is, so I could be without realizing it. I did a quick google on that, and I don't think so. The script shows me that the navigation 'show subsites' option is unchecked, and so does the web page areanavigationsettings.aspx, so it's not just powershell reporting cached or old info. The setting is getting changed, but not applied/saved.
    – QMKevin
    Commented Feb 15, 2012 at 18:46
  • Go to Site Settings -> Site Collection Output Cache and then look for the profile listed for Anonymous and for Authenticated. If both say "Disabled" then you are not using caching. However, if a profile other than "Disabled" is listed, that would mean that the pages themselves are being cached for a specified amount of time (usually 3 minutes) and that any changes would not appear during that time.
    – Dave Wise
    Commented Feb 15, 2012 at 18:52
  • Thanks for the steps. Both Anonymous Cache Profile and Authenticated Cache Profile are set to Disabled. Your point about 3 minute sis interesting. I contacted the authoring of the article where I got the script (and adapted it), and he said that the updates where a timer job. That said, it's been hours now, and still the sites are not having the 'show subsites' change applied.
    – QMKevin
    Commented Feb 15, 2012 at 19:24
  • The only other suggestion I have would be to try doing a $pubWeb.AllowUnsafeUpdates = true; prior to the .Update()
    – Dave Wise
    Commented Feb 15, 2012 at 20:07

1 Answer 1


Try doing a .AllowUnsafeUpdates = true; prior to the .Update()

  • That worked for me, with a subtle change. In my code above, I changed $pubWeb.Update() to be $web.AllowUnsafeUpdates = 1; $web.Update() i.e. I did not update $pubWeb, but $web instead, with your suggestion as well.
    – QMKevin
    Commented Feb 15, 2012 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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