Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 :)

share|improve this question
    
Are you using output caching? –  Dave Wise Feb 15 '12 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 Feb 15 '12 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 Feb 15 '12 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 Feb 15 '12 at 19:24
    
The only other suggestion I have would be to try doing a $pubWeb.AllowUnsafeUpdates = true; prior to the .Update() –  Dave Wise Feb 15 '12 at 20:07
show 1 more comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
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 Feb 15 '12 at 21:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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