使用 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 目前不適用於由中國 21Vianet 營運的 Office 365 使用者。使用德國雲端的 Microsoft 365 使用者是使用 German Telekom 資料信任者,則也不適用此工具。但是,其資料位置不在德國資料中心的德國使用者則可使用此工具。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 硬碟:150 GB 的可用空間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 可轉散發套件Microsoft 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 高速網際網路連線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 可轉散發套件Microsoft 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. 請使用您現有的 Active Directory 或是其他將帳戶新增到 Microsoft 365 的選項來佈建您的 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

    請確認當中有 DLL,如果您使用的是 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
    如果您以 NoShow 模式開始進行移轉,正在執行的 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":[

            ]
         }
      }
   ]
}