SharePoint: Como exportar/importar un sitio en la misma colección de sitios (o en una diferente)!

Si os encontráis con la necesidad de exportar un sitio e importarlo dentro de la misma colección (por un cambio en el diseño de la arquitectura de la información), es algo que podéis conseguir de forma muy sencilla mediante los comandos PowerShell Export-SPWeb e Import-SPWeb. En concreto, el siguiente script PowerShell (Descargable desde How to Export / Import a SharePoint Site) facilita esta tarea:

   1: ############################################################################################################################################

   2: # Script that allows to export/import a Site.

   3: # Required Parameters: 

   4: #    ->$sSiteToExport: SharePoint Site to be Exported

   5: #    ->$sSiteToImport: SharePoint Site to be Imported

   6: #    ->$sBackupPath: Path where the Backup is stored

   7: #    ->$sOperationType: Operation Type (Backup or Restore)

   8: ############################################################################################################################################

   9:  

  10: If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) 

  11: { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

  12:  

  13: $host.Runspace.ThreadOptions = "ReuseThread"

  14:  

  15: #Definition of the function that exports/imports a SharePoint Site

  16: function ExportImportSharePointSite

  17: {

  18:     param ($sSiteToExport,$sSiteToImport,$sOperationType,$sBackupPath)

  19:     try

  20:     {

  21:         switch ($sOperationType) 

  22:         { 

  23:         "Export" {

  24:             Write-Host "Doing the export for $sSiteToExport !!" -ForegroundColor Blue

  25:             Export-SPWeb -Identity $sSiteToExport -Path $sBackupPath -Force -Confirm:$false

  26:             Write-Host "Export operation for $sSiteToExport successfully completed!!" -ForegroundColor Blue

  27:  

  28:             } 

  29:         "Import" {

  30:             Write-Host "Doing the import for $sSiteToImport" -ForegroundColor Blue

  31:             New-SPWeb -Url $sSiteToImport -Template "STS#0" -Language 3082

  32:             Import-SPWeb -Identity $sSiteToImport -Path $sBackupPath

  33:             Write-Host "Import Operation for $sSiteToImport successfully completed!!" -ForegroundColor Blue

  34:             }         

  35:         default {

  36:             Write-Host "Requested Operation not valid!!" -ForegroundColor DarkBlue            

  37:             }

  38:         }

  39:        

  40:     }

  41:     catch [System.Exception]

  42:     {

  43:         write-host -f red $_.Exception.ToString()

  44:     }

  45: }

  46:  

  47: Start-SPAssignment –Global

  48: #Calling the function

  49: $sSiteToExport="http://<Site_To_Export>/"

  50: $sSiteToImport="http://<Site_To_Import>"

  51: $sBackupPath="<Backup_Path>\<Backup_File>.cmp"

  52: #Export

  53: ExportImportSharePointSite -sSiteToExport $sSiteToExport -sBackupPath $sBackupPath -sOperationType "Export"

  54:  

  55: #Import

  56: ExportImportSharePointSite -sSiteToImport $sSiteToImport -sBackupPath $sBackupPath -sOperationType "Import"

  57: Stop-SPAssignment –Global

  58:  

  59: Remove-PSSnapin Microsoft.SharePoint.PowerShell