Move a #SharePoint 2010 sub site to a different location on the same farm #SP2010 #PS2010 #PowerShell

June 28, 2012 at 4:41 pm | Posted in Administration, PowerShell | 3 Comments
Tags: , , ,

Recently a query came up on the Project Server forums asking how to move a SharePoint site from the PWA site collection to another site collection. Please note this was not a Project Site. For this question I created a simple PowerShell script that will export the site and import it into the specified location. Even though this example is for a site in the PWA site collection, it will work for a site in any SharePoint 2010 site collection providing the same site templates, features etc. are available.

The script is available to download from the Microsoft Script Center:

Below is a walkthrough on using and executing the script.

Firstly download the script and set the variables:

# set variables
$exportfolder = "C:\Site exports"         – Specify the folder to be created, this is where the export files will be created
$exportfile = "\site_export.cmp"        – Specify the export file name
$exportsite = "http://vm353/PWA/PAULMATHERTESTSITE"       – Specify the URL of the site that you want to move
$exportlocation = $exportfolder+$exportfile      – This does not need to be updated
$importlocation = "http://vm353/PAULMATHERTESTSITE"   – Specify the location where you want the site to be imported

The next part of the script gets the exported site’s template as this is needed to create the placeholder site later on:

#get export site’s template
$web = Get-SPWeb $exportsite
$webTemp =  $web.WebTemplate
$webTempID = $web.Configuration
$webTemplate = "$webTemp#$webTempID"

Worthing noting is that you need to use the Configuration property as the template ID rather than the WebTemplateID property as the WebTemplateID will always contain the original ID for the first template Microsoft created. For example a Team Site template ID is STS#0, but the WebTemplateID property for a Team Site will contain a 1, the Configuration property will contain the correct ID, in this case a 0.

The final part of the script is does the export and import, the comments above each line advise what that part of the script is doing.

#create export folder
$null = New-Item $exportfolder -type directory
#export site
Export-SPWeb $exportsite –Path $exportlocation -IncludeUserSecurity -IncludeVersions 4
Write-host "$exportsite has been exported to $exportlocation"
#create new site ready for import
$null = New-SPWeb $importlocation -Template "$webTemplate"
Write-host "$importlocation created ready for import"
#import site
Import-SPWeb $importlocation –Path $exportlocation -IncludeUserSecurity –UpdateVersions 2
Write-host "$exportsite has been imported to $importlocation" -foregroundcolor "Green"

Now lets have a walkthrough and move a site, in the example I have a Team site called “PAULMATHERTESTSITE” that is below the PWA site collection, I want to move this to the top level root site collection. For this example the variables above are correct. Open PowerShell on the Application server and navigate to the location of the ps1 file, in this case it is on my desktop:


Press Enter to execute the script:


A copy of the site should now exist in the new location.

As always, this script is provided as is with no warranties etc. use at your own risk and test on a test environment before using on a production environment.

#ProjectServer save from Project Professional failed #PS2010 #SP2010 #MSProject

June 27, 2012 at 11:38 am | Posted in Administration, Fixes, Installation | 1 Comment
Tags: , ,

Just a quick post as a reminder, I was recently at a client where projects failed to save to Project Server. The key error shown in Project Professional and in the Project Server queue was:

error id =”12005”

error= System.Data.SqlClient.SqlException: Execution of user code in the .Net Framework is disabled. Enable “clr enabled” configuration option

The error states the exact issue, CLR needed to be enabled on the SQL Server. The steps to enable CLR are documented here:

Update #SharePoint absolute URLs with relative URLs using #PowerShell #ProjectServer #PS2010 #SP2010

June 18, 2012 at 4:34 pm | Posted in Administration, Fixes, Functionality, PowerShell | 1 Comment
Tags: , , , ,

I recently came across an issue with a document library URL on the project sites after the client rolled over the Production environment to the Test farm. When the Project site template was created, a link to a central document library on another site collection was added to the quick launch. The absolute URL was used rather than the relative URL, subsequently all project sites created from that template have the full URL. This obviously works fine for the Production environment but when the project sites are migrated to the Test environment with the environment rollover, the links for this document library point to the Production environment.

Rather than going to each project site and updating the URL manually to the relative URL or asking one of our developers to create a console app to do this, I thought I’d try with PowerShell.

Below is the PowerShell script:

# Script will update the absolute Url on the quick launch link under the specified heading
# with the relativeUrl

# add SharePoint snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue
#set variables
$site = "http://vm353/PWA"
$QuickLaunchHeading = "Libraries"
$absoluteUrl = "http://vm353/Shared documents"
$relativeUrl = "/Shared Documents"
foreach ($web in (Get-SPSite  $site | Get-SPWeb -Limit All))
    $node = $web.Navigation.QuickLaunch | where { $_.Title -eq $QuickLaunchHeading }

    foreach($childNode in $node.Children | where { $_.URL -eq ($absoluteUrl) })
        Write-host "Updating" $childNode.Title "on the following site" $web.Url
        $childNode.URL = $relativeUrl
Write-host "Finished!" -foregroundcolor "Green"

The script above requires four variables to be updated for your environment:

$site = "http://vm353/PWA"           – The site collection URL where the Project Sites exist
$QuickLaunchHeading = "Libraries"  – The quick launch heading where the link exists
$absoluteUrl = “http://vm353/shared documents”   – The URL for the link that needs updating
$relativeUrl = "/Shared Documents"  – The correct relative URL for the link

As you can see in this example for my testing, my project sites have a link under the Libraries heading to the root site’s shared documents. The script will show what links have been updated as shown below:


Whilst the example above is showing document library links, this script will update any quick launch links providing the correct heading and absolute URL variables are set. The script will also work for non PWA site collections.

The script is available for download from the script gallery, link below:

As always, this script is provided as is with no warranties etc. use at your own risk and test on a test environment before using on a production environment. 

Blog at
Entries and comments feeds.