Tuesday, May 13, 2014

Promote sub site to separate site collection

To move a sub site to its own site collection, we can follow this link, but there are a few pitfalls.

1. Need to specify "IncludeUserSecurity" parameter for both "export" and "import";

2. May need to copy customized master pages, css, etc. to the new site collection, manually, through SharePoint designer;

3. Because the GUID of the spweb and the splists are changed, we lost all associations of declarative workflows. All non-declarative workflows are gone.

4. The root site of the new site collection needs to use the same web template as the original sub site.

5. Don't forget to clean up the extra SharePoint user groups in the new site collection.


Below is the PowerShell scripts. Hope it can save you some time.

Any comments welcome!


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
cls

$SiteOwner = "domain\spsiteadmin"

function Promote-SubSite([string]$webURL, [string]$siteURL, [string]$webName)
{
    $web = Get-SPWeb -Identity $webURL
    $FilePath = "\\fileserver\ExportedSubSite\$webName.cmp"
    Export-SPWeb -Identity $webURL -Path $FilePath -IncludeUserSecurity -IncludeVersions all

    $WebTemplateName = $web.WebTemplate + "#" + $web.Configuration
    Write-Host "WebTemplateName" $WebTemplateName
    $template = Get-SPWebTemplate $WebTemplateName
    
    #Remove-SPSite -Identity $SiteUrl –Confirm:$False
    New-SPSite -Url $SiteUrl -OwnerAlias $SiteOwner -Template $template

    Import-SPWeb $siteURL –Path $FilePath –UpdateVersions Overwrite -ActivateSolutions -IncludeUserSecurity
}

Start-SPAssignment -Global
cls

Promote-SubSite "http://sharepointserver/sites/site1/subsiteA/subsiteA1" "http://sharepointserver/sites/subsiteA1" "subsiteA1"

Stop-SPAssignment -Global

Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
Read-Host

No comments:

Post a Comment