Using PowerShell to Convert SharePoint 2007 List Templates (STP) for SharePoint 2010

This method of converting SharePoint 2007 list templates for use in SharePoint 2010 is not supported by Microsoft. Use at your own risk. Your mileage may vary.

SharePoint 2007 List Templates in SharePoint 2010

I recently needed to move a number of list templates from SharePoint 2007 to SharePoint 2010. Unfortunately, SharePoint 2010 just doesn’t support this. The only supported method to move these lists across is to upgrade the whole content database. That just wasn’t an option for me, so I needed to find another way.

Luckily, I discovered an excellent blog post by Tom (Belgium) that describes a method for getting SharePoint 2007 list templates working in SharePoint 2010.

Tom’s basic method is:

  1. Extract the contents of the STP file (it’s really just a CAB file)
  2. Edit the manifest.xml file, changing the ProductVersion element from 3 to 4
  3. Repackage the STP file

I have had success with this method for both templates for lists and document libraries.

Automating the process with PowerShell

After having success with Tom’s method, I decided to see if I could automate the process since I had a number of list templates I needed to convert. I am by no means a PowerShell guru, but the following script gets the job done:

#Usage: UpgradeListTemplates.ps1 C:\path\to\YourTemplate.stp
if ($args.length -eq 0)
    write-warning "You must supply a file name";
    $stpFile = $args[0]
$FileExists = Test-Path $STPFile
If ($FileExists -ne $True)
    write-warning "You must supply a valid file name";
# Create a temp directory
$ParentDir = Split-Path $STPFile -Parent
$OutputDir =  $ParentDir + "\output"
New-Item $OutputDir -type directory | out-null
# Extract the contents of the STP file
& expand.exe -i $stpFile $OutputDir -f:* | out-null
$ManifestXML = $OutputDir + "\manifest.xml"
$ManifestExists = Test-Path $ManifestXML
If ($ManifestExists -ne $True)
    write-warning "Could not find manifest.xml";
# Update the manifest.xml ProductVersion element
(Get-Content $ManifestXML) |
Foreach-Object {$_ -replace "<ProductVersion>3</ProductVersion>", "<ProductVersion>4</ProductVersion>"} |
Set-Content $ManifestXML
$ExtractedItems = Get-ChildItem -Path $OutputDir -Name
#Create a MakeCAB directive file
$Directive = $OutputDir + "\directive.ddf"
$CabFileName = Split-Path $StpFile -Leaf
New-Item $Directive -type file | out-null
Add-Content $Directive ".OPTION EXPLICIT"
Add-Content $Directive (".Set CabinetNameTemplate=" + $CabFileName)
Add-Content $Directive ".Set DiskDirectoryTemplate=CDROM"
Add-Content $Directive ".Set CompressionType=MSZIP"
Add-Content $Directive ".Set MaxDiskSize=CDROM"
Add-Content $Directive ".Set Cabinet=on"
Add-Content $Directive ".Set Compress=on"
Add-Content $Directive (".Set DiskDirectory1=" + (Convert-Path($OutputDir)).tostring())
foreach ($Item in $ExtractedItems)
    $ExtractedFilePath = Convert-Path ($OutputDir + "\" + $Item)
    Add-Content $Directive """$ExtractedFilePath"""
# Create the new CAB in the temp directory
& makecab.exe -f ($OutputDir + "\directive.ddf") | out-null
# Move the new STP file to the original directory, with "Upgraded" added to the file name
$BaseFileName = $CabFileName.split(".")[0]
$BaseFileNameExtension = $CabFileName.split(".")[1]
$NewFileName = $ParentDir + "\" + $BaseFileName + "Upgraded." + $BaseFileNameExtension
Move-Item -path ($OutputDir + "\" + $CabFileName) -destination $NewFileName
# Clean up temp items
Remove-Item $OutputDir -recurse
Remove-Item ((Get-Location).tostring() + "\setup.inf")
Remove-Item ((Get-Location).tostring() + "\setup.rpt")
Write-Host "Finished upgrading " $STPFile " for SharePoint 2010"
Write-Host "Upgraded file is" $NewFileName

You can also download the script here: UpgradeListTemplate.ps1

Related posts:

2 thoughts on “Using PowerShell to Convert SharePoint 2007 List Templates (STP) for SharePoint 2010”

Leave a Reply

Your email address will not be published. Required fields are marked *