当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 将所有列表和库从一个站点导出导入到另一个站点

作者:精品下载站 日期:2024-12-14 13:49:42 浏览:13 分类:玩电脑

使用 PowerShell 将所有列表和库从一个站点导出导入到另一个站点


要求是将所有 SharePoint 列表和库从一个站点复制并粘贴到另一个站点。虽然“将列表另存为模板”是一种方法,但它不适用于较大的列表,而且非常耗时。使用中央管理导出方法也浪费我的时间。

[玩转系统] 使用 PowerShell 将所有列表和库从一个站点导出导入到另一个站点

解决方案:我们可以使用 PowerShell 脚本复制并粘贴 SharePoint 列表。

在 SharePoint 2013/2016 中使用 PowerShell 导出文档库:

语法:
Export-SPWeb -Path -ItemURL -IncludeUserSecurity -IncludeVersions All

例如。


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

使用 PowerShell 在 SharePoint 2013 中导入文档库:

语法:
Import-SPWeb -path -force -IncludeUserSecurity -UpdateVersions Overwrite

例如。


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

使用 PowerShell 将所有列表和库从一个站点导出导入到另一个站点:

使用此 PowerShell 脚本从站点导出所有列表。


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\"

该脚本帮助我将所有列表从高度自定义且损坏的网站移动到干净的 SharePoint 网站。这是另一个 PowerShell 脚本,用于在站点之间复制粘贴所有列表和库:使用 PowerShell 在站点之间复制 SharePoint 列表或库

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯