PowerShell to change the UIVersion on a subweb in SharePoint 2010

Recently ran into the need to revert a specific web back to the SharePoint 2007 UI after an upgrade to SharePoint 2010.  The main reason for the change was a custom masterpage that was not ready for the 2010 styles and ribbon.  After the UI was upgraded, the masterpage rendering was pretty bad.  The Site Actions menu would render behind the contents of the page, the layout was completely out of whack.

I put together a couple lines of PowerShell that will do this for a specific web.  In our case, we upgraded the database using Mount-SPContentDatabase –UpdateUserExperience, then ran the PowerShell below to revert just that one subweb.  This allowed all the other content to pick up the 2010 UI.  For example, if you have a subweb at https://teams/sub1/sub2 that needs to be the 2007 UI, you could use:

    1: $web = Get-SPWeb https://sharepoint.domain.com/sub1/sub2
    2: $web.UIVersion = 3
    3: $web.Update()

 

After the initial upgrade testing, we found there were subwebs underneath sub2 that also needed the 2007 UI.  I put together the following which enumerates all the subwebs under a specific subweb and switches them to the 2007 UI..  Put the script into a PS1 file and run it from there.

    1: function ChangeUIVersion($web)
    2: {
    3:         $web.UIVersion = 3
    4:     $web.Update()
    5: }
    6:  
    7: function ProcessSubWebs($currentWeb)
    8: {
    9:         ChangeUIVersion($currentWeb)
   10:  
   11:     foreach($sub in $currentWeb.Webs)
   12:     {
   13:         ChangeUIVersion($sub)
   14:  
   15:         if($sub.Webs.Count -gt 0)
   16:         {
   17:             ProcessSubWebs($sub)    
   18:         }
   19:     }
   20: }
   21:  
   22: ProcessSubWebs(Get-SPWeb -identity https://sharepoint.domain.com/sub1/sub1/)
   23: