Búsqueda de sitios web

Exportar-Importar todas las listas y bibliotecas de un sitio a otro usando PowerShell


El requisito es copiar y pegar todas las listas y bibliotecas de SharePoint de un sitio a otro. Si bien "Guardar lista como plantilla" es un enfoque, no funciona para listas más grandes y requiere mucho tiempo. Usar el método de exportación de la Administración Central también me mata el tiempo.

Solución: Podemos copiar y pegar listas de SharePoint usando el script de PowerShell.

Exportar biblioteca de documentos usando PowerShell en SharePoint 2013/2016:

Sintaxis:
Export-SPWeb -Path -ItemURL -IncludeUserSecurity -IncludeVersions All

P.ej.


Export-SPWeb https://sharepoint.crescent.com/Teams/2015-ESG/ -Path "D:\Documents.cmp" -ItemURL "Documents" -IncludeUserSecurity -IncludeVersions All 

Importe la biblioteca de documentos en SharePoint 2013 usando PowerShell:

Sintaxis:
Import-SPWeb <> -path <> -force -IncludeUserSecurity -UpdateVersions Sobrescribir

P.ej.


Import-SPWeb https://sharepoint.crescent.com/Teams/2016-ESG/" -Path "D:\Documents.cmp" -force -IncludeUserSecurity -UpdateVersions Overwrite

Exportar: importar todas las listas y bibliotecas de un sitio a otro usando PowerShell:

Utilice este script de PowerShell para exportar todas las listas de un sitio.


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Export-AllLists($WebURL, $ExportPath)
{
   #Get the source web
   $web = Get-SPWeb $WebURL

   #Check the Local Folder export Lists
    
   #Get all lists - Exclude System lists
   $ListCollection = $web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.Author.LoginName -ne "SHAREPOINT\system") }

   #Iterate through each list and export
   foreach($list in $ListCollection)
    {
        Write-host "Exporting: " $list.Title
        #Remove : from List title - As we can't name a file with : symbol
        $ListTitle = $list.Title.Replace(":",[string]::Empty)
        Export-SPWeb $WebURL -ItemUrl "/$($list.RootFolder.Url)" -IncludeUserSecurity -IncludeVersions All -path ($ExportPath + $ListTitle+ ".cmp") -nologfile
    } 
}

#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Import-AllLists($WebURL, $ImportPath)
{
   #Get the Target web
   $web = Get-SPWeb $WebURL

   #Check the Local Folder export Lists
    
   #Get all File Backups to Import
   $FilesCollection = Get-ChildItem $ImportPath

   #Iterate through each file and import
   foreach($File in $FilesCollection)
    {
        Write-host "Importing: " $File.Name
        Import-SPWeb $webURL -path $ImportPath$File -includeusersecurity -UpdateVersions Overwrite -nologfile
    } 
}

#Call the function to export
Export-AllLists "https://sales.crescent.com/" "D:\Backup\"
#To import, Use:
#Import-AllLists "https://marketing.crescent.com/" "D:\Backup\"

Este script me ayudó a mover todas las listas de un sitio corrupto y altamente personalizado a un sitio limpio de SharePoint. Aquí hay otra secuencia de comandos de PowerShell para copiar y pegar todas las listas y bibliotecas entre sitios: Copiar lista o biblioteca de SharePoint entre sitios con PowerShell

Artículos relacionados