Freigeben über


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 = "https://intranet.contoso.com/SubSite"

$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

  • Anonymous
    January 01, 2003
    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"

  • Anonymous
    January 01, 2003
    my understanding is that, this script will convert sub-site in a site collection, is it correct?

  • Anonymous
    January 01, 2003

  1. yes. 2. it's a file to hold the exported web data that we will import into the new site collection.
  • Anonymous
    January 01, 2003
    what is oldWeb.CMP??

  • Anonymous
    June 10, 2013
    Could you help a total newb like me? I have no idea where i would put this code rlbpeck@gmail.com

  • Anonymous
    November 18, 2013
    Does it migrate all sub-sites within the site?

  • Anonymous
    January 08, 2015
    this shall work on sharepoint online?

  • Anonymous
    February 06, 2015
    Will this work on SharePoint Online?

  • Anonymous
    October 12, 2015
    Hi Just want to move share-point sub site to another site. Is it work for my requirement or not?

  • Anonymous
    February 23, 2016
    There are many issues with an exported and imported site. Page layout is one of the major ones.