So your moving to SharePoint 2010. You’ve got some beautiful sites out there in your 2007 environment and need to create solutions out of them so that users can use them in your new SharePoint 2010 environment. You followed the instructions in my last blog article (). As such you’ve decided to give up on SharePoint and go back to Email as your collaboration and management solution.
Oh I have been there, so let’s see if we can make it easier.
Problem 1
Uploading multiple files to the Site Template Gallery is not permissible so I have to upload each one, one at a time. I have 60 of them, please let the asteroid hit now!
Problem 2
Creating multiple sites at a time based upon each site template you have in the gallery. That should only take about a day of clicking and typing in the title and URL. Why are you doing this to me!
Problem 3
You’ve upgraded your server, now you have to get the sites back in to WSP form. You have go into every site setting page and click the stupid link “Save Site as a Template”. I say stupid because by now, you never want to see SharePoint again.
Okay so let’s ease our pain, and while we wait, catch up on the latest episodes of Dancing with the Stars on Hulu. (No I don’t watch it really, I was actually watching Human Target)
First: On your server, make sure you have setup the 12/Bin directory up as a path in your Environment variables. We will need this for our command prompt. (Start Menu, Right-Mouse-Click Computer – Choose Properties, Advanced System Settings, Environment Variables, Path (Edit) – Add – “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN”, OK, OK.
Problem 1 and Solution
Use the command prompt with a for loop and the stsadm command to add all the site templates to the global site template gallery. To do this, open your command prompt as an Administrator. Also, place all the STPs files within a directory on your server that you will be accessing from your command prompt. In case you are wondering, if you haven’t already done so, in the command prompt locate the directory where your stp files are.
BEFORE YOU DO THIS: Make sure all site templates do not have spaces or unsupported special characters. (“, ~, {, }, ?, <, >, :, *, #, \, $, /, <space>, |)
Command Time
for %i in (*.stp) do stsadm –o addtemplate–filename %i –title %i
Congrats you have just added all the site templates to your site.
Problem 2 Solution
Use the same loop to created a web in SharePoint with your uploaded template.
Command time (Replace myserver with your siteurl)
for %i in (*.stp) do stsadm –o createweb –url http://myserver/%i –sitetemplate %i –title %i
Congrats you have just created a site for every one of your Site Templates. Now you can upgrade your server.
Problem 3 Solution
To PowerShell we go. We will use a complex script that will go to your site, grab all the subsites and make solutions out of them. Then you will go to the Solution gallery and download them. Easy Peasee, Lemon Squeezee. For this you will need to open SharePoint Management Shell in Administration mode.
PowerShell time (Replace myserver with your siteurl)
.\CreateSiteTemplates.ps1 ‘http://myserver/’ 1 0 1 1 ‘FullPortability’
Congrats you have just created a WSP for every one of your sites and can now download them from the Solutions gallery located in your site collection.
NOTE: I didn’t create this for 2007 as we already had our site templates created and they are available in the gallery, so we just downloaded them. I figured everyone else is the same, so I didn’t need this same script for 2007. If you want a script for 2007, let me know and I’ll build one.
If an error occurs during solution creation, you can match the error and possible resolution to my previous article. If those errors don’t match to the red error, please check the ULS log files to learn more, fix the issue, and then execute this script using the direct URL for the site that failed.
I designed the PowerShell to remove “.stp” from the WSP so that the Solution Names look nice.
The PowerShell Explained
The script that I wrote is designed to look at your site or sites and export the site(s) to the solution gallery. This takes the place of having to do one site at a time. A second benefit is you can use this to export a site to a solution with Full Portability. This removes the need to have the original solution installed on the server where the new site template will be used.
To Download the PowerShell Script Click Here
You must execute this from a PowerShell Command window which is registered for the Microsoft.SharePoint.PowerShell cmdlet. You must also do so as an Administrator.
Use:
.\CreateSiteTemplates.ps1 –SiteURL <SiteURL:http://myserver/site> –SaveData <0/1> –SaveCurrentSite <0/1> –SaveSubSites <0/1> –CheckForSolutions <0/1> –SExportMode <FullReuse/FullPortability>
-SiteURL(REQUIRED) the URL of the Site that a solution will be created from or will be used as the parent URL for all sub sites from which solutions will be automatically created.
-SaveData is the boolean indication if data should be saved from the site that the solution is created from. (Enter 0 for false, 1 for true)
-SaveCurrentSite is the boolean indication that you would like a solution to be created from the site used as the parent site. The parent site is the site entered from your Site URL. (Enter 0 for false, 1 for true)
-SaveSubSites is the boolean indication that you would like a solution created for all sub sites found beneath the parent site. (Enter 0 for false, 1 for true)
-CheckForSolutions is the boolean indication that you would like the script to look to see if a solution was already created for the site and if so delete it. If false the solution will not be deleted and a number will be added to the end of the solution name to indicate it is a duplicate if a duplicate is found. (Enter 0 for false, 1 for true)
-SExportMode is the type of export that should be completed when creating the Solution. FullReuse indicates that you will require the user to have the original solution that the site was created from and require that the original solution be installed and activated on the server. FullPortability indicates that you wish for all dependencies to be loaded into solution so that the solution can be deployed on another server without the original solution being installed and activated.
Examples:
.\CreateSiteTemplates.ps1 ‘http://myserver/AnnouncementServiceV1.0.stp/’ (Will save the current site with data as a fully portable solution, making sure to delete any already existing solutions with the same name.)
.\CreateSiteTemplates.ps1 ‘http://myserver/TheAwesomeApp’ 1 0 1 1 ‘FullPortability’ (Will save all sub sites of the current site with data, as a fully portable solution making sure to delete an already existing solutions with the same name.)
.\CreatesiteTemplates.ps1 –SiteURL ‘http://myserver/AnotherAwesomeApp’ –SaveData 0 –SaveCurrentSite 1 –SaveSubSites 0 –CheckForSolution 1 –SExportMode ‘FullReuse’ (Will save all sub sites of the current site with no data, and the created solution will require any dependant solutions to already be installed an activated on the server before use. Before save it will not attempt to delete any solutions which already exist with the same name but will append a number after the solution name to indicate it is a duplicate solution.)