使用 PowerShell 迁移到 SharePointMigrate to SharePoint using PowerShell

本文介绍了基于 SharePoint 迁移工具 (SPMT) 迁移引擎的新 PowerShell cmdlet。它们可用于将文件从 SharePoint 2010 和 SharePoint 2013 本地文档库和列表项以及文件共享迁移到 Microsoft 365 中。若要了解与 SharePoint 迁移相关的当前所有 PowerShell cmdlet,请参阅 Microsoft SharePoint 迁移工具 cmdlet 参考This article is about the new PowerShell cmdlets based on the SharePoint Migration Tool (SPMT) migration engine. They can be used to move files from SharePoint 2010 and SharePoint 2013 on-premises document libraries and list items, and file shares to Microsoft 365. For information on all current PowerShell cmdlets relating to SharePoint migration, please see the Microsoft SharePoint Migration Tool cmdlet reference.

PowerShell cmdlet 的功能与 SharePoint 迁移工具相同。The PowerShell cmdlets provide the same functionalities as the SharePoint Migration Tool.

备注

这些 PowerShell cmdlet 暂不适用于由世纪互联在中国运营的 Office 365 的用户。同样,它也不适用于使用数据托管方 德国电信 的德国云的 Microsoft 365 的用户。不过,数据位置不在德国数据中心的德国用户可以使用它们。These PowerShell cmdlets are currently not available for users of Office 365 operated by 21Vianet in China. They are also not available for users of Microsoft 365 with the German cloud using the data trustee, German Telekom. However, they are supported for users in Germany whose data location is not in the German datacenter.

系统要求System requirements

为实现最佳性能而建议满足的要求Recommended requirements for best performance

说明Description 建议Recommendation
CPUCPU 64 位四核处理器或更高64-bit Quad core processor or better
RAMRAM 16 GB16 GB
本地存储Local Storage 硬盘:150GB 可用空间Hard disk: 150 GB free space
操作系统Operating system Windows Server 2016 Standard 或 DatacenterWindows Server 2016 Standard or Datacenter
Windows Server 2012 R2Windows Server 2012 R2
Windows 10 客户端Windows 10 client
.NET Framework 4.6.2.NET Framework 4.6.2
Microsoft Visual C++ 2015 RedistributableMicrosoft Visual C++ 2015 Redistributable OneNote 迁移所必需Required for OneNote migration

重要

必须具有 PowerShell 5.0 和 .NET Framework 4.6.2 或更高版本才支持迁移文件路径(不超过 400 个字符)。PowerShell 5.0 and .NET Framework 4.6.2 or higher are required to support the migration of file paths of up to 400 characters.

最低要求(预期性能较差)Minimum requirements (expect slow performance)

说明Description 最低要求Minimum requirement
CPUCPU 64 位 1.4 GHz 双核处理器或更高64-bit 1.4 GHz 2-core processor or better
RAMRAM 8 GB8 GB
本地存储Local Storage 硬盘:150 GB 可用空间Hard disk: 150 GB free space
网卡Network card 高速 Internet 连接High-speed Internet connection
操作系统Operating system Windows Server 2008 R2Windows Server 2008 R2
Windows 7Windows 7
Windows 8 或 8.1Windows 8 or 8.1
.NET Framework 4.6.2.NET Framework 4.6.2
Microsoft Visual C++ 2015 RedistributableMicrosoft Visual C++ 2015 Redistributable OneNote 迁移所必需。Required for OneNote migration.
PowerShellPowerShell 必须有 PowerShell 5.0 或更高版本,才能支持迁移最多 400 个字符的文件路径。PowerShell 5.0 or higher required to support migration of file paths of up to 400 characters.

准备工作Before you begin

  1. 为 Microsoft 365 预配现有 Active Directory,或预配其他用于将帐户添加到 Microsoft 365 的工具之一。有关详细信息,请参阅 Microsoft 365 与本地环境集成将用户添加到 Microsoft 365 企业应用版Provision your Microsoft 365 with either your existing active directory or one of the other options for adding accounts to Microsoft 365. See Microsoft 365 integration with on-premises environments and Add users to Microsoft 365 Apps for business for more information.

  2. 打开文件夹:Open the folder:

    $env:UserProfile\Documents\WindowsPowerShell\Modules\Microsoft.SharePoint.MigrationTool.PowerShell$env:UserProfile\Documents\WindowsPowerShell\Modules\Microsoft.SharePoint.MigrationTool.PowerShell

    请确保里面有DLLs,如果你使用OneDrive,你可能需要将WindowsPowershell文件夹复制到OneDrive / 文档中。Make sure you have DLLs inside of it, if you're using OneDrive you may need to copy the WindowsPowershell Folder into OneDrive / Documents.

  3. 从此位置运行以下 PowerShell 命令From this location, run the following PowerShell command

    Import-Module Microsoft.SharePoint.MigrationTool.PowerShell
    

创建和初始化迁移会话Create and initialize a migration session

  • Register-SPMTMigrationRegister-SPMTMigration
    此 cmdlet 可用于创建和初始化迁移会话。初始化在会话一级配置迁移设置。如果未定义特定的设置参数,将使用默认设置。注册会话后,可以向会话添加任务并开始迁移。This cmdlet creates and then initializes a migration session. The initialization configures migration settings at the session level. If no specific setting parameters are defined, default settings will be used. After a session is registered, you can add a task to the session and start migration.

添加迁移任务Add a migration task

  • Add-SPMTTaskAdd-SPMTTask
    此 cmdlet 可用于向已注册的迁移会话添加新迁移任务。目前,允许添加以下三种不同类型的任务:文件共享任务、SharePoint 任务和 JSON 定义的任务。注意:禁止添加重复任务。 Use this cmdlet to add a new migration task to the registered migration session. Currently there are three different types of tasks allowed: File share task, SharePoint task and JSON defined task. Note: Duplicate tasks are not allowed.

删除任务Remove a task

  • Remove-SPMTTaskRemove-SPMTTask
    此 cmdlet 可用于从已注册的迁移会话中删除现有迁移任务。Use this cmdlet to remove an existing migration task from the registered migration.

开始迁移Start your migration

返回当前会话对象Return the object of current session

  • Get-SPMTMigrationGet-SPMTMigration
    返回当前会话对象。这包括当前任务状态和当前会话级别设置。当前任务状态包括: Return the object of the current session. This includes the status of current tasks and current session level settings. Current task status includes:
    • 已扫描文件数Count of scanned files
    • 已迁移文件数Count of migrated files
    • 任何迁移错误消息Any migration error messages

停止当前迁移Stop your current migration

在控制台中显示迁移状态详细信息Show your migration status details in the console

  • Show-SPMTMigrationShow-SPMTMigration
    如果是在 NoSh ow 模式下开始迁移,运行 Show-SPMTMigration cmdlet 会在控制台中显示任务 ID、数据源位置、目标位置和迁移状态。按 Ctrl+C 可返回到 NoShow 模式。 If you start the migration in NoShow mode, running the Show-SPMTMigration cmdlet will display the task ID, data source location, target location and migration status in the console. Pressing Ctrl+C will return to NoShow mode.

删除迁移会话Remove the migration session

示例应用场景Sample Scenarios

示例 1:IT 管理员添加 SharePoint 本地任务,并在后台开始迁移。Example 1: IT admin adds a SharePoint on-prem task and starts migration in the background.

#Define SharePoint 2013 data source#
$Global:SourceSiteUrl = "http://YourOnPremSite/"
$Global:OnPremUserName = "Yourcomputer\administrator"
$Global:OnPremPassword = ConvertTo-SecureString -String "OnPremPassword" -AsPlainText -Force
$Global:SPCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:OnPremUserName, $Global:OnPremPassword
$Global:SourceListName = "SourceListName"

#Define SharePoint target#
$Global:SPOUrl = "https://contoso.sharepoint.com"
$Global:UserName = "admin@contoso.onmicrosoft.com"
$Global:PassWord = ConvertTo-SecureString -String "YourSPOPassword" -AsPlainText -Force
$Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord
$Global:TargetListName = "TargetListName"

#Define File Share data source#
$Global:FileshareSource = "YourFileShareDataSource"

#Import SPMT Migration Module#
Import-Module Microsoft.SharePoint.MigrationTool.PowerShell

#Register the SPMT session with SharePoint credentials#
Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force

#Add two tasks into the session. One is SharePoint migration task, and another is File Share migration task.#
Add-SPMTTask -SharePointSourceCredential $Global:SPCredential -SharePointSourceSiteUrl $Global:SourceSiteUrl  -TargetSiteUrl $Global:SPOUrl -MigrateAll
Add-SPMTTask -FileShareSource $Global:FileshareSource -TargetSiteUrl $Global:SPOUrl -TargetList $Global:TargetListName

#Start Migration in the console. #
Start-SPMTMigration

示例 2:IT 管理员要将迁移从后台“NoShow 模式”切换为前台模式。运行下面的 cmdlet,这样就能在控制台中查看迁移进度。Example 2: IT admin wants to bring the migration from the background "NoShow mode" to the foreground, run below the cmdlet, so he can see the migration progress in the console.

Show-SPMTMigration

示例 3:IT 管理员想要通过加载 .csv 文件执行批量迁移。Example 3: IT Admin wants to do a bulk migration by loading a .csv file. 此示例中的示例文件是 SPMT.csv。The sample file in this example is SPMT.csv.

Load CSV;
$csvItems = import-csv "C:\spmt.csv" -Header c1,c2,c3,c4,c5,c6
ForEach ($item in $csvItems)
{
    Write-Host $item.c1
    Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath $item.c6
}

spmt.csv文件中定义了两个迁移任务。Two migration tasks are defined in the file of spmt.csv.

D:\MigrationTest\Files\Average_1M\c,,,https://SPOSite.sharepoint.com,Documents,Test
C:\work\Powershell\negative,,,https://SPOSite.sharepoint.com/,Documents,DocLibrary_SubfolderName

通过加载一个JSON文件进行批量迁移的代码片段:Code snippets for bulk migration by loading one JSON file:

#Load JSON:
$jsonItems = Get-Content -Raw -Path  "C:\spmt.json" | ConvertFrom-Json
ForEach ($taskItem in $jsonItems.Tasks)
{
    $jsonString = ConvertTo-Json $taskItem -Depth 100
    Add-SPMTTask -JsonDefinition $jsonString -SharePointSourceCredential $onpremCredential
}

spmt.json文件中定义了三个迁移任务。Three migration tasks are defined in the file of spmt.json.

{
   "Tasks":[
      {
         "SourcePath":"http://On-prem/sites/test",
         "TargetPath":"https://YourSPO.sharepoint.com",
         "Items":{
            "Lists":[
               {
                  "SourceList":"list-01",
                  "TargetList":"list-01"
               }
            ],
            "SubSites":[

            ]
         }
      },
      {
         "SourcePath":"http://On-prem/sites/test",
         "TargetPath":"https://YourSPO.sharepoint.com",
         "Items":{
            "Lists":[
               {
                  "SourceList":"list-02",
                  "TargetList":"list-02"
               }
            ],
            "SubSites":[

            ]
         }
      },
      {
         "SourcePath":"http://On-prem/sites/test",
         "TargetPath":"https://YourSPO.sharepoint.com",
         "Items":{
            "Lists":[
               {
                  "SourceList":"doclib-01",
                  "TargetList":"doclib-01"
               }
            ],
            "SubSites":[

            ]
         }
      }
   ]
}