Wednesday, September 21, 2016

How to move Child Subsite to another site collection using PowerShell


Add SharePoint snapin

Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue

Set variables - FYI exportfolder will throw an error if folder is already created.

$exportfolder = "E:\backup\NAME" $exportfile = "\s.cmp" $exportsite = "http://test/hr/site 101" $exportlocation = $exportfolder+$exportfile $importlocation = "http://test2/hr/site 101"

Get export site's template

$web = Get-SPWeb $exportsite $webTemp = $web.WebTemplate $webTempID = $web.Configuration $webTemplate = "$webTemp#$webTempID" $web.Dispose()

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"

No comments:

Post a Comment