共用方式為


使用 PowerShell 移轉至 SharePoint

本文是關於以 SharePoint 移轉工具 (SPMT) 移轉引擎為基礎的新 PowerShell Cmdlet。 它們可用來將檔案從 SharePoint 2010 和 SharePoint 2013 內部部署文檔庫和清單專案,以及檔案共用移至 Microsoft 365。 如需與 SharePoint 移轉相關的所有目前 PowerShell Cmdlet 相關信息,請參閱 Microsoft SharePoint 移轉工具 Cmdlet 參考。

PowerShell Cmdlet 提供與 SharePoint 移轉工具相同的功能。

注意事項

這些 PowerShell Cmdlet 目前不適用於在中國由 21Vianet 營運 Office 365 使用者。

系統需求

描述 建議
CPU 64 位元四核心或更高等級處理器
RAM 16 GB
本機儲存空間 硬碟:150 GB 的可用空間
作業系統 Windows Server 2016 Standard 或 Datacenter
Windows Server 2012 R2
Windows 10 客戶
端 .NET Framework 4.6.2
Microsoft Visual C++ 2015 可轉散發套件 OneNote 移轉需求

重要事項

需要 PowerShell 5.0x 和 .NET Framework 4.6.2 或更新版本,才能支援最多 400 個字元的檔案路徑移轉。

最低需求 (效能較低)

描述 基本需求
CPU 64 位元 1.4 GHz 雙核心或更高等級處理器
RAM 8 GB
本機儲存空間 硬碟:150 GB 的可用空間
網路卡 高速網際網路連線
作業系統 Windows Server 2008 R2
Windows 7
Windows 8 或 8.1
.NET Framework 4.6.2
Microsoft Visual C++ 2015 可轉散發套件 OneNote 移轉需求。
PowerShell 支援最多 400 個字元之檔案路徑移轉所需的 PowerShell 5.x。 不支援 PowerShell 6.0 或更新版本。

長路徑問題的因應措施

使用 SPMT PowerShell 時,您可能會在路徑超過 260 個字元的來源檔案上遇到掃描失敗。 若要解決此問題,您可以修改系統登錄,讓 PowerShell 讀取長路徑檔案。

啟註冊 編輯器,流覽至 "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework",新增金鑰 "AppContext"。 然後在索引鍵下新增 2 個字串值。

  • 數值名稱: Switch.System.IO.BlockLongPaths 值數據: false

  • 數值名稱: Switch.System.IO.UseLegacyPathHandling 值數據: false

開始之前

  1. 使用現有的 Active Directory 或將帳戶新增至 Microsoft 365 的其他其中一個選項,布建您的 Microsoft 365。 如需詳細資訊,請參閱 Microsoft 365 與內部部署環境整合將使用者新增至 Microsoft 365 Apps 商務版

  2. 開啟資料夾: $env:UserProfile\Documents\WindowsPowerShell\Modules\Microsoft.SharePoint.MigrationTool.PowerShell 請確定其中有 DLL。 如果您使用 OneDrive,則必須將 WindowsPowershell 資料夾複製到 $env:UserProfile\OneDrive - Microsoft\Documents

  3. 從此位置執行下列 PowerShell 命令:

    Import-Module Microsoft.SharePoint.MigrationTool.PowerShell
    

建立和初始化移轉工作階段

此 Cmdlet 會建立並初始化移轉會話。 初始化會在會話層級設定移轉設定。 如果沒有定義特定的設定參數,則會使用預設設定。 註冊會話之後,您可以將工作新增至會話並開始移轉。

新增移轉工作

使用此 Cmdlet 將新的移轉工作新增至已註冊的移轉會話。 目前允許三種不同類型的工作:檔案共用工作、SharePoint 工作和 JSON 定義的工作。 注意:不允許重複的工作。

移除工作

使用此 Cmdlet 從註冊的移轉中移除現有的移轉工作。

開始移轉

此 Cmdlet 會啟動已註冊的SPMT移轉。

傳回目前工作階段的物件

傳回目前會話的物件。 此 Cmdlet 包含目前工作和目前工作層級設定的狀態。 目前的工作狀態包括:

S - 掃描的檔案計數

  • 已移轉檔案的數目
    • 任何移轉錯誤訊息

停止目前的移轉

此 Cmdlet 會取消目前的移轉。

在主控台中顯示移轉狀態詳細資料

如果您以 NoShow 模式開始移轉,執行 Show-SPMTMigration Cmdlet 會在控制台中顯示工作識別碼、數據源位置、目標位置和移轉狀態。 選取 Ctrl+C 會將顯示器傳回 NoShow 模式。

移除移轉工作階段

使用此 Cmdlet 刪除移轉工作階段。

範例案例

範例 1: IT 系統管理員會新增 SharePoint 內部部署工作,並在背景中開始移轉。

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

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

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

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

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

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

#Start Migration in the console. #
Start-SPMTMigration

範例 2: IT 系統管理員想要將移轉從背景「NoShow 模式」移轉到前景,並在 Cmdlet 下方執行,以便在控制台中顯示移轉進度。

Show-SPMTMigration

範例 3:IT 管理員 想要藉由載入 .csv 檔案來進行大量移轉。 在此範例中的樣本檔案是 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 檔案中定義了兩個移轉工作。

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

透過載入一個 JSON 檔案進行大量移轉的程式碼片段:

#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 檔案中定義了三個移轉工作。

{
   "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":[

            ]
         }
      }
   ]
}

範例 4: 顯示移轉進度

這些範例展示如何顯示移轉專案的進度。 Get-SPMTMigration 會傳 回目前會話的物件,其中包含目前的工作狀態和目前的會話層級設定。

目前工作的狀態包括:

  • 掃描的檔案計數。
  • 篩選出的檔案計數。
  • 已移轉的檔案計數。
  • 失敗的檔案計數。
  • 目前工作的移轉進度 (0 ~ 100) 。
  • 目前的工作狀態。
  • 如果有任何移轉錯誤訊息, 則為 。

# Start migration in the background
Start-SPMTMigration -NoShow

# Get the object of current migration
$session = Get-SPMTMigration

# Query migration status every 5 seconds until migration is finished
while ($session.Status -ne "Finished")
{
Write-Host $session.Status

    # Query migration progress of each tasks
    Foreach ($taskStatus in $session.StatusOfTasks)
    {
        $taskStatus.MigratingProgressPercentage
}

    Start-Sleep -Seconds 5
}