This one will actually back up the named Site Collection, then restore it using the new managed path. One thing most people don't mention is this won't necessarily put the Site Collection back in the same database it came from - so keep an eye on your databases in the Manage Content Databases area of Central Admin. You want to be sure the Site Collection you're moving is in a content database that has enough Site Collections available before it hits a warning. You also want to make sure you don't have another content db out there that has a much higher number of available slots.
SharePoint is lazy - and it'll go where the most room is. Keep an eye on that.
Anyway, here's the script.
***
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Source Site Collection URL
$sourceURL = Read-Host “Enter the Source URL”
#Get the Target Site Collection URL
$targetURL = Read-Host “Enter the Destination URL”
#Location for the backup file
$backupPath = Read-Host “Where do you want the backup stored”
Try
{
#Set the Error Action
$ErrorActionPreference = "Stop"
Write-Host "Backing up the Source Site Collection..."-ForegroundColor DarkGreen
Backup-SPSite $sourceURL -Path $backupPath -force
Write-Host "Backup Completed!`n"
#Delete source Site Collection
Write-Host "Deleting the Source Site Collection..."
Remove-SPSite -Identity $sourceURL -Confirm:$false
Write-Host "Source Site Deleted!`n"
#Restore Site Collection to new URL
Write-Host "Restoring to Target Site Collection..."
Restore-SPSite $targetURL -Path $backupPath -Confirm:$false
Write-Host "Site Restored to Target!`n"
#Remove backup files
Remove-Item $backupPath
}
catch
{
Write-Host "Operation Failed. Find the Error Message below:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
}
finally
{
#Reset the Error Action to Default
$ErrorActionPreference = "Continue"
}
write-host "Process Completed!"
No comments:
Post a Comment