SharePoint – migrate a sub-site into its own Site Collection

# Move-SPwebToNewSPsite.ps1
# simple outline sample of how to migrate a sub-site into its own new Site Collection.
# definately not comprehensive, but should give you an idea of what to do.
# NO I have not exported Alerts or Workflows. Food for thought!

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$ExportShare = "\\SERVERNAME\Backup\oldWeb.CMP"
$OldSPWebUrl = ""

$newMgdPath = "Sites"
$newSPSiteName = "TheNewSite"
$Descr = "the newSite collection"

try {

  $oldSPWeb = Get-SPWeb $oldSPwebUrl

  $SPWebApp = $oldSPWeb.Site.WebApplication
  $oldSubWebUrl = $OldSPWeb.ServerRelativeUrl
  $Owner = $OldSPWeb.AssociatedOwnerGroup.Users[0].LoginName

  Export-SPweb -Identity $oldSPWeb -Path $ExportShare

  $newSiteUrl = "{0}{1}/{2}" -f $SPWebApp.Url, $newMgdPath, $newSPSiteName
  if (-NOT (get-spmanagedpath -Identity $newMgdPath -WebApplication $SPWebApp)) {
   new-spmanagedpath -RelativeURL $newMgdPath -WebApplication $SPWebApp

  $newSPSite = New-SPsite -Url $newSiteUrl -OwnerAlias $Owner -Template "STS#0" -Description $Descr
  $newSPWeb  = $newSPSite.RootWeb
  Import-SPweb $newSPWeb -Path $ExportShare

  Remove-SPweb $oldSPWeb -Confirm:$false

 catch {
  "Error caught: {0}" -f $Error[0]


Comments (10)
  1. Anonymous says:

    Tried this on SharePoint 2013 and it almost worked.

    It backed up the site and it imported it into a new site collection. I can see it as a site collection when I check the "view all site collections"

    I made myself a site collection administrator and then when going to browse to it, I get the famous message from SharePoint "Something went Wrong"

  2. my understanding is that, this script will convert sub-site in a site collection, is it correct?

  3. LukeBrennan says:

    1. yes. 2. it's a file to hold the exported web data that we will import into the new site collection.

  4. what is oldWeb.CMP??

  5. Rachael says:

    Could you help a total newb like me?

    I have no idea where i would put this code

  6. Trupti Gondaliya says:

    Does it migrate all sub-sites within the site?

  7. Satya says:

    this shall work on sharepoint online?

  8. Siddhesh says:

    Will this work on SharePoint Online?

  9. Sandeep Poonia says:

    Hi Just want to move share-point sub site to another site. Is it work for my requirement or not?

  10. Robert More says:

    There are many issues with an exported and imported site. Page layout is one of the major ones.

Comments are closed.

Skip to main content