Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Using PowerShell to control Visual Upgrade
December 10
Using PowerShell to control Visual Upgrade

Visual Upgrade is capability in SharePoint 2010 that allows you to view upgraded sites as they looked in SharePoint until you are ready to view them in their full SharePoint 2010 glory. Your reasons for this might be user education, or the need to update customizations you have. The Visual Upgrade is scoped at the web level, so all the pages in a web can be rendered as SharePoint 2007 or as SharePoint 2010. There are a few ways to control this. The easiest way is inside of the UI itself, and that is probably how Site Collection administrators will control how webs are rendered. Another option is Windows PowerShell. PowerShell is a great way to take care of this if you have to work with a lot of webs. It has looping capabilities that make this very easy. One scenario were you might want to do this is what a Database Attach upgrade. In this situation you have a SharePoint 2007 (SP2 or later) content database that you attach to an existing SharePoint 2010 farm. While you can force the SharePoint 2010 on the content of this content database when you attach it, that gives you less flexibility. If you choose to preserve the SharePoint 2007 UI you'll need to switch it to the SharePoint 2010 interface eventually. The PowerShell script below will take a Content Database name and determine all the Site Collections in that db. It will then walk through all the webs in those Site Collections and set them to the SharePoint 2010 interface. Let's take a look at it:

$db = Get-SPContentDatabase WSS_Content_SharePoint_2007

$db.Sites | Get-SPWeb -limit all | ForEach-Object {$_.UIversion = 4; $_.UIVersionConfigurationEnabled = $false; $_.update()}

The first line creates a variable, $db, and assigns it an object that represents the content database. Once we have that object, we can use the Sites property to get a list of all the site collections stored in it. Using pipes, we pipe the Site Collection objects through Get-SPWeb to get each web (SPWeb) for each site (SPSite). Once we get the web, we can set the UIversion property of that web to the version we want displayed. Setting the value to 4 gives us the SharePoint 2010 interface. If you want the SharePoint 2007 interface, set UIversion to 3. The next part, $_.UIVersionConfigurationEnabled = $false removes the "Visual Upgrade" option from the Site Actions dropdown. This keeps users from going in and setting the UI back to the SharePoint 2007 interface. Finally we need to execute $_.update() to write our changes to the web.

That's all there is to it. Now all the webs in that upgraded Content Database are using the SharePoint 2010 interface.

tk

Comments

SPAssignmentCollection

Todd - you may want to update your sample to use the SPAssignmentCollection to avoid running out of memory when looping through all the SPSite and SPWeb objects that could be returned by doing this.

-GL
 on 2/3/2010 12:29 PM

A Faster Way

There's a faster way to upgrade the content a site collection at a time. You can read more at http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.visualupgradewebs(office.14).aspx. This is available through script or from the UI for Site Collection administrators. This avoids the issue of handling each SPWeb individually.
 on 2/15/2010 4:25 AM

Re: Using PowerShell to control Visual Upgrade

thanks, i applied the power shell script and run it with the new UI of SharePoint 2010
 on 8/12/2010 2:29 AM

Worked better than MS Article

I went to the MS Article http://technet.microsoft.com/en-us/library/ff607998.aspx#section2 and tried to do all the subsites but kept giving me errors on PS. Your solution worked like a charm.

J
 on 11/9/2010 4:54 PM

Re: Worked better than MS Article

Thanks J, I appreciate it. I dare you to leave a comment on that article and tell them my blog post is better. :)

tk
Todd O. KlindtNo presence information on 11/14/2010 8:28 PM

SubSite Level

Todd - Is there a way we can enable visual upgrade on one subsite and all of the child subsites down stream through PowerShell
 on 12/1/2010 12:45 PM

Re: SubSite Level

Sure. You could use Get-SPWeb to get a variable for the subsite. Then loop through that subsite's .webs property to loop through its subsites. Something like this:

$w = get-spweb http://sharepoint/sites/team/subsite
$w.webs | ForEach-Object {$_.UIversion = 4; $_.UIVersionConfigurationEnabled = $false; $_.update()}

Something like that.

tk

Todd O. KlindtNo presence information on 12/15/2010 9:22 AM

Disposing

TK, great post mate. Little worried about on a site with say 15,000 Webs that this would leak like a sieve. I do love the simplicity of the piping in PowerShell, but using Get-SPWeb really needs to dispose of the #_ instance each time. Does PowerShell have a way to facilitate this in the foreach
 on 12/16/2010 8:13 PM

Re: Disposing

I'm no authority on the subject of disposal, so this might all be hogwash. :) From what I understand, disposal is not a problem if you keep your PowerShell to a single line. When you do that, PowerShell disposes it all at the end.

If you have blocks of PowerShell then you can use Start-SPAssignment to control disposal.

tk
Todd O. KlindtNo presence information on 12/17/2010 11:16 PM

Killer

I got a ton of errors about access denied but the changes are applied. Thanks for the post!
 on 3/11/2011 12:08 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 Please Support my Sponsors