Shared Points

items of some interest

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

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

  • Comments 5
  • Likes

# 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 = "http://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
  • <p>my understanding is that, this script will convert sub-site in a site collection, is it correct?</p>

  • <p>what is oldWeb.CMP??</p>

  • <p>1. yes. 2. it&#39;s a file to hold the exported web data that we will import into the new site collection.</p>

  • <p>Could you help a total newb like me?</p> <p>I have no idea where i would put this code rlbpeck@gmail.com</p>

  • <p>Does it migrate all sub-sites within the site?</p>

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment