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 UpdateNavigation($sub) ProcessSubWebs($sub) $sub.Update() $sub.Dispose() } } } 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 $pubWeb.Update() } ProcessSubWebs(Get-SPWeb -identity http://myserver/site1) Write-Host -ForegroundColor red "FINISHED" Any ideas?
[update based on Dave Wise's answer below]
Replace
$pubWeb.Update() with
$web.AllowUnsafeUpdates = 1; $web.Update() worked for me! Thanks Dave :)