Monthly Archives: April 2013

Migrating Master Pages from MOSS 2007 to SharePoint 2010

I’ve mentioned before that I am doing a complex migration from MOSS 2007 to SharePoint 2010 and I came across an absolute doozy of an issue over the last couple of days. I doubt anyone else will come across this, but it worth noting, if not just for my sanity, but also in case it crops up somewhere else.

The source 2007 site was a publishing site with a heavily customised Master Page. The Master Page containing some controls in it for navigation and so on – unfortunately the source code for these controls were written in Visual Studio 2005 and deployed, well, somehow. I rebuilt the controls in VS2010 and a nice WSP for deployment.

There remains the problem of getting it to work in the new environment. The old control would not work, giving the SharePoint Screen of Death. No problem, I don’t need it anyway. I copied the old 2007 Master Page, uploaded it into 2010 and worked on it with SharePoint Designer to run the new control. All is hunky dory.

Until we come to roll out. Plan was to do a migration via Attach Database, then put my new Master Page into the system, flip over to it and all is well.

The migration goes OK, the site pops up with the expected Master Page error, I go into SPD to upload the new custom MP, check it in, requires Approval so open the page in the browser and…

Error. The Approval page still uses the old, failing, MP.

I can change the MP using the GUI but I can’t flip it to the new Master page because it hasn’t been Approved and I can’t Approve it because that relies on a Master Page that fails.

OK, so off to Powershell I go and Approve the page in the back end. Back to the Change Master Page page and my custom MP either does not appear in the dropdown or gives me a warning that it is set for SharePoint v4 (2010) and not the v3 (2007) UI that we are keeping.

The problem is this. If you upload a Master Page to the Master Page Gallery, the UI Version is automatically set to v4 – SharePoint 2010. This is a problem if you are using the v3 GUI – either the new MP will not appear for selection and if it does, it is set to v4. You can’t change this because your Master Page is faulty and you can’t get to the List through the browser. The value is not available in SPD to change.

After a lot of faffing, the solution I found is this.

1. Using Powershell, change the MasterPage Url to default.master (or something other than your current MP, but still v3).
2. Go into the Master Page Gallery and edit the new custom Master Page item you added and set the UI Version to 3 (not both 3 and 4, but 3).
3. Back into Powershell and change the MasterPage Url to your new custom Master Page.

It will all work now.

The key fact to take away is that by default in SharePoint 2010, any Master Page uploaded to the Gallery is set to v4 even if your site is running as v3.

Advertisements

Quota Templates in Powershell

I’m currently working on a few migration type things and need to set up some quota templates. ┬áThe actual sizes of those templates is TBA, so I figure a set of quick Powershell functions will help me set them up as an when I need them.

The majority of the code is from Ryan Dennis at SharePointRyan.com, though I believe he built on work from Gary LaPointe. ┬áBut then, doesn’t everyone?

function New-SPQuotaTemplate {
<#
.Synopsis
    This advanced function creates a new Site Quota Template.
.Example
    C:\PS>New-SPQuotaTemplate -Name "Custom" -StorageMaximumLevel 2GB -StorageWarningLevel 1GB -UserCodeMaximiumLevel 100 -UserCodeWarningLevel 75
     
    This example creates an SP Quota Template called Custom with a maximum size of 2GB and a warning size of 1GB. Sandboxed solutions are limited to 100, with a warning level of 75.
.Example
    C:\PS>New-SPQuotaTemplate -Name "Custom" -StorageMaximumLevel 4GB -StorageWarningLevel 3GB
     
.Notes
    Name: New-SPQuotaTemplate
    Author: Ryan Dennis
    Last Edit: 4/27/2012
    Keywords: Quota Template, Quotas and Locks
	Modified By: Mike Landers, 02/04/2013
.Link
http://www.sharepointryan.com
http://twitter.com/SharePointRyan
#Requires -Version 2.0
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][String]$Name,
[Parameter(Mandatory=$true)][Int64]$StorageMaximumLevel,
[Parameter(Mandatory=$true)][Int64]$StorageWarningLevel,
[Parameter(Mandatory=$false)][System.Double]$UserCodeMaximumLevel,
[Parameter(Mandatory=$false)][System.Double]$UserCodeWarningLevel
)
# Instantiate an instance of an SPQuotaTemplate class #
Write-Verbose "Instantiating an instance of an SPQuotaTemplate class"
$Quota = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
# Set the Properties #
Write-Verbose "Setting properties on the Quota object"
$Quota.Name = $Name
$Quota.StorageMaximumLevel = $StorageMaximumLevel
$Quota.StorageWarningLevel = $StorageWarningLevel
$Quota.UserCodeMaximumLevel = $UserCodeMaximumLevel
$Quota.UserCodeWarningLevel = $UserCodeWarningLevel
# Get an Instance of the SPWebService Class #
Write-Verbose "Getting an instance of an SPWebService class"
$Service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
# Use the Add() method to add the quota template to the collection #
Write-Host "Adding the $($Name) Quota Template to the Quota Templates Collection" -foreground Green
$Service.QuotaTemplates.Add($Quota)
# Call the Update() method to commit the changes #
$Service.Update()
Write-Host "Quota Template $Name added successfully" -foreground Green
}

function Get-SPQuotaTemplate {
<#
.Synopsis
 This advanced function retrieves a SharePoint Site Quota Template.
.Example
 C:\PS>Get-SPQuotaTemplate -Name "Custom"
 
 This example retrieves a SharePoint Quota Template called Custom in the current farm.
.Example
 C:\PS>Get-SPQuotaTemplate
 
 This example retrieves all SharePoint Quota Templates in the current farm.
.Notes
 Name: Get-SPQuotaTemplate
 Author: Ryan Dennis
 Last Edit: 5/10/2012
 Keywords: Quota Template, Quotas and Locks
.Link
http://www.sharepointryan.com
http://twitter.com/SharePointRyan
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)][String]$Name
)
$Templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates
if ($Name)
 {
 $Templates | Where-Object {$_.Name -eq $Name}
}
else
{
 $Templates
}
}

function Remove-SPQuotaTemplate {
<#
.Example
 C:\PS>Remove-SPQuotaTemplate -Name "Custom"
 
 This example removes a SharePoint Quota Template called Custom in the current farm.
 .Link
http://stuffaboutsharepoint.com
http://twitter.com/micaituk

#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][String]$Name
)
$Templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.QuotaTemplates
$TemplateCheck = $Templates | Where-Object {$_.Name -eq $Name}
if ($TemplateCheck -ne $null)
   { 
   	Write-Host "`nFound Template $Name" -foreground Green
	$Service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
	$Template = $Service.QuotaTemplates[$Name]
	Write-Host "Deleting Template $Name" -foreground Green
	$Service.QuotaTemplates.Delete($Name)
	$Service.Update()
	Write-Host "Template $Name deleted successfully`n" -foreground Green
	Write-Host
   }
else
   {
    Write-Host "`nTemplate $Name does not exist, no changes made`n" -foreground Red
   }
}