使用 PowerShell Cmdlet 將內部部署內容上傳到 SharePointUpload on-premises content to SharePoint using PowerShell cmdlets

注意

SharePoint 移轉工具 (SPMT) 可協助簡化移轉程序。The SharePoint Migration Tool (SPMT) helps simplify your migration process. SPMT 提供類似精靈的體驗,引導您移轉 SharePoint Server 小組網站或網路檔案共用至 Microsoft 365。SPMT provides a wizard-like experience to guide you through migrating SharePoint Server team sites or network file shares to Microsoft 365. 它可供所有 Microsoft 365 使用者使用:下載 SPMTIt is available to all Microsoft 365 users: Download SPMT.

重要

SharePoint 移轉工具目前不適用於由中國 21Vianet 運作的 Office 365 使用者。The SharePoint Migration Tool isn't currently available for users of Office 365 operated by 21Vianet in China.

此文章展示如何使用 SharePoint 移轉 PowerShell Cmdlet,將內部部署檔案共用的內容移轉到 Microsoft 365。This article shows how to use SharePoint Migration PowerShell cmdlets to migrate content from an on-premises file share to Microsoft 365.

SharePoint 移轉 PowerShell Cmdlet 專門用來移動內部部署的檔案共用內容。SharePoint Migration PowerShell cmdlets are designed to move on-premises content from file shares. 它們需要最少的 CSOM 呼叫,並使用 Azure 暫時 Blob 儲存體來處理大型資料移轉。They require minimal CSOM calls and use Azure temporary Blob Storage to handle large migrations of data.

必要條件Prerequisites

  • 支援的作業系統:Supported operating systems:

    • Windows 7 Service Pack 1Windows 7 Service Pack 1
    • Windows 8Windows 8
    • Windows Server 2008 R2 SP1Windows Server 2008 R2 SP1
    • Windows Server 2008 Service Pack 2Windows Server 2008 Service Pack 2
    • Windows Server 2012、Windows Server 2012 R2Windows Server 2012, Windows Server 2012 R2
  • Windows PowerShell 4.0Windows PowerShell 4.0

注意

權限:您必須是移轉目標的網站集合系統管理員。Permissions: You must be a site collection administrator on the sit that you're targeting.

開始之前Before you begin

步驟 1:安裝 SharePoint Online 管理命令介面Step 1: Install the SharePoint Online Management Shell

  1. 解除安裝所有舊版本的 SharePoint Online 管理命令介面。Uninstall all previous versions of the SharePoint Online Management Shell.

  2. 下載並安裝 SharePoint Online 管理命令介面。Download and install SharePoint Online Management Shell.

  3. 開啟 SharePoint Online 管理命令介面,然後選取 [以管理員身分執行]Open SharePoint Online Management Shell, and select Run as Administrator.

步驟 2:設定您的工作目錄Step 2: Set up your working directory

在開始移轉之前,您需要使用兩個空資料夾以設定工作目錄。Before you start the migration, you need to set up your working directory with two empty folders. 這些資料夾不需要太多磁碟空間,因為它們只包含 XML。These folders don't need much disk space, as they'll only contain XML.

  1. 建立暫存套件資料夾。Create a temporary package folder.

  2. 建立最終套件資料夾。Create a final package folder.

步驟 3:決定位置和認證Step 3: Determine locations and credentials

識別您的認證以及來源檔案、目標檔案和網站的位置。Identify your credentials and the locations of your source files, target files, and web.

在您的本機電腦上,開啟 SharePoint Online 管理命令介面。On your local computer, open SharePoint Online Management Shell. 執行以下命令,但插入您的值:Run the following commands, but insert your values:

$cred = (Get-Credential admin@contoso.com)
$sourceFiles = '\\fileshare\users\charles'
$sourcePackage = 'C:\migration\CharlesDocumentsPackage_source'
$targetPackage = 'C:\migration\CharlesDocumentsPackage_target'
$targetWeb = 'https://contoso-my.sharepoint.com/personal/charles_contoso_com'
$targetDocLib = 'Documents'

New-SPOMigrationPackage -SourceFilesPath $sourceFiles -OutputPackagePath $sourcePackage -TargetWebUrl $targetWeb -TargetDocumentLibraryPath $targetDocLib -IgnoreHidden -ReplaceInvalidCharacters

步驟 4:從內部部署檔案共用建立新的內容套件Step 4: Create a new content package from an on-premises file share

在本步驟中,您將從檔案共用建立新的移轉套件。In this step, you create a new migration package from a file share. 要從檔案共用建立內容套件,New-SPOMigrationPackage 命令讀取來源路徑指定的內容清單,並產生 XML 以執行移轉。To create a content package from a file share, the New-SPOMigrationPackage command reads the list of content targeted by the source path and generates XML to do the migration.

下列參數除非標記為選用,否則皆為必要:The following parameters are required unless marked optional:

  • SourcefilesPath:指向您計劃移轉的內容。SourcefilesPath: Points to the content you plan to migrate.

  • OutputPackagePath:指向您的暫存資料夾。OutputPackagePath: Points to your Temporary folder.

  • TargetWebUrl:指向您的目的地網站。TargetWebUrl: Points to your destination web.

  • TargetDocumentLibraryPath︰指向網站內的文件庫。TargetDocumentLibraryPath: Points to the document library inside the web.

  • IgnoreHidden:跳過隱藏檔案 (選用)IgnoreHidden: Skip hidden files (optional).

  • ReplaceInvalidCharacters:盡可能修正無效字元 (選用)ReplaceInvalidCharacters: Fix invalid characters when possible (optional).

範例:Example:

以下範例示範如何從檔案共用建立新的套件。The following example shows how to create a new package from a file share. 它略過隱藏的檔案並取代檔案/資料夾名稱中不支援的字元。It ignores hidden files and replaces unsupported characters in file/folder names.

    New-SPOMigrationPackage -SourceFilesPath $sourceFiles -OutputPackagePath $sourcePackage -TargetWebUrl $targetWeb -TargetDocumentLibraryPath $targetDocLib -IgnoreHidden -ReplaceInvalidCharacters`

步驟 5:轉換內容套件以供您的目標網站使用Step 5: Convert the content package for your target site

使用 ConvertTo-SPOMigrationTargetedPackage 命令轉換暫存資料夾中產生的 SML。Use the ConvertTo-SPOMigrationTargetedPackage command to convert the SML generated in your temporary folder. 此命令會將一組新的目標移轉套件中繼資料檔案儲存到目標目錄。It saves a new set of targeted migration package metadata files to the target directory. 這就是最終套件。This is the final package.

注意

您的目標網站集合管理員認證,會用來蒐集資料以連線到資料網站集合。Your target site collection administrator credentials are used to gather data to connect to the data site collection.

此命令需要輸入 6 個參數 (其他則為選用):There are six required parameters to enter (others are optional):

  • ParallelImport:指示工具使用平行執行緒來最佳化效能。ParallelImport: Instructs the tool to use parallel thread optimize performance.

  • SourceFiles:指向套件之來源內容檔案的目錄位置。SourceFiles: Points to the directory location of the package's source content files.

  • SourcePackagePath:指向您的暫存套件資料夾。SourcePackagePath: Points to your temporary package folder.

  • OutputPackagePath:指向您的最終套件資料夾。OutputPackagePath: Points to your final package folder.

  • Credentials:具備目的地網站系統管理員權限的 SharePoint 認證。Credentials: SharePoint credential that has admin rights to the destination site.

  • TargetWebUrl:您的目的地網站之 URL。TargetWebUrl: URL of your destination web.

  • TargetDocumentLibraryPath:目的地文件庫的路徑。TargetDocumentLibraryPath: Path to your destination library.

範例:Example:

本範例示範如何在目標網站集合中查閱資料,以將套件轉換為目標套件。This example shows how to convert a package to a targeted one by looking up data in the target site collection. 爲提高檔案共用移轉效能,它使用 -ParallelImport 參數。To boost file share migration performance, it uses the -ParallelImport parameter.

$finalPackages = ConvertTo-SPOMigrationTargetedPackage -ParallelImport -SourceFilesPath $sourceFiles -SourcePackagePath $sourcePackage -OutputPackagePath $targetPackage -Credentials $cred -TargetWebUrl $targetWeb -TargetDocumentLibraryPath $targetDocLib`

步驟 6:提交要匯入的內容Step 6: Submit content to import

在本步驟中, Invoke-SPOMigrationEncryptUploadSubmit 命令會在目標網站集合中建立新的移轉工作,並傳回代表 JobID 的 GUID。In this step, the Invoke-SPOMigrationEncryptUploadSubmit command creates a new migration job in the target site collection and then returns a GUID that represents the JobID. 此命令為每一項工作將加密的來源檔案與資訊清單上傳到暫存的 Azure Blob 儲存體中。This command uploads encrypted source files and manifests into temporary Azure Blob Storage per job.

需要輸入 4 個參數。There are four required parameters to enter. 其他則爲選用。Others are optional.

  • TargetwebURL:指向目的地網站。TargetwebURL: Points to the web of the destination.

  • SourceFilesPath:指向要匯入的檔案。SourceFilesPath: Points to the files to import.

  • SourcePackagePath:指向要匯入檔案的最終資訊清單。SourcePackagePath: Points to the final manifest of the files to import.

  • Credentials:具備目的地網站之網站集合系統管理員權限的 SharePoint 認證。Credentials: The SharePoint credentials that have Site Collection Administrator rights to the destination site.

範例 1:Example 1:

本範例示範如何提交套件資料來建立新的移轉工作。This example shows how to submit package data to create a new migration job.

 $job = Invoke-SPOMigrationEncryptUploadSubmit -SourceFilesPath $sourceFiles -SourcePackagePath $targetPackage -Credentials $cred -TargetWebUrl $targetWeb

範例 2:Example 2:

本範例示範如何提交套件資料來為平行匯入建立新的移轉工作。This example shows how to submit package data to create new migration jobs for parallel import.

$jobs = $finalPackages | % {Invoke-SPOMigrationEncryptUploadSubmit -SourceFilesPath $_.FilesDirectory.FullName -SourcePackagePath $_.PackageDirectory.FullName -Credentials $cred -TargetWebUrl $targetWeb}

針對每個提交的工作,Invoke Cmdlet 會隨著工作傳回這些屬性:For each submitted job, the Invoke cmdlet returns these properties as part of a job:

  • JobId:SPO 中的工作識別碼。JobId: ID of the job in SPO.

  • ReportingQueueUri:儲存移轉之即時進度訊息的 SharePoint Azure 佇列。ReportingQueueUri: SharePoint Azure queue that stores the real-time progress messages of the migration.

  • Encryption:將內容上傳到 Azure 使用的加密金鑰和方法。Encryption: Encryption key and method used for uploading the content to Azure. 解密佇列訊息和匯入記錄時需要此金鑰。This key is required when you decrypt the queue messages and import logs.

如果您使用自己的 Azure 儲存體帳戶,請使用 Set-SPOMigrationPackageAzureSourceSubmit-SPOMigrationJob 將內容上傳至您的儲存體。If you're using your own Azure Storage account to upload content into your storage, use Set-SPOMigrationPackageAzureSource and Submit-SPOMigrationJob.

重要

如果您選擇使用您的 Azure 儲存體,這可能會產生頻寬費用。If you choose to use your Azure Storage, you could incur Bandwidth charges. 收費將取決於您的 Azure 方案類型和移轉大小。Charged would depend on your Azure offer type and migration size. 如需一般價格,請參閱 頻寬價格For general prices, refer to bandwidth pricing.

(選用) 步驟 7:處理及監控 SharePoint 移轉(Optional) Step 7: Process and monitor your SharePoint migration

提交工作後,只有 Azure 和 SharePoint 有所互動,以擷取內容並將其移轉到目的地。After the job is submitted, only Azure and SharePoint interact to fetch and migrate the content to the destination. 此程序屬於計時器工作,也就是先到者先處理的佇列形式。This process is timer-job based, which means it's in a queue on a first-come, first-served basis. 此流程不會封鎖同一個人佇列其他工作。This process doesn't prevent the same person from queuing other jobs.

如果沒有其他正在執行的工作,則可能會有 1 分鐘的延遲。If no other jobs running are running, there may be a 1-minute delay.

檢查工作狀態Check job status

要檢查工作的狀態,請使用步驟 6 中傳回的 EncryptionKey 檢視在 Azure 儲存體帳戶中張貼的即時更新資訊。To check the status of your job, use the EncryptionKey returned in step 6 to view the real-time updates posted in the Azure Storage account.

檢視記錄View logs

如果您使用自己的 Azure 儲存體帳戶,則可以檢視 Azure 儲存體中資訊清單容器中發生的所有事件的記錄檔。If you're using your own Azure Storage account, you can view logs of everything that happened in the manifest container in the Azure Storage. 在此階段,如果您不想留在 Azure 中做為備份,可以放心刪除這些容器。At this stage, it's safe to delete those containers, if you don't want to keep them as backup in Azure.

如果發生錯誤或警告,系統會在資訊清單容器中建立 .err.won 檔案。If there were errors or warnings, .err or .won files are created in the manifest container.

如果您使用步驟 6 中由 Invoke-SPOMigrationEncryptUploadSubmit 建立的暫存 Azure 儲存體,則可以透過使用「Event」值 JobLogFileCreate 解密 Azure 佇列訊息來取得匯入記錄檔案 SAS URL。If you're using the temporary Azure Storage created by Invoke-SPOMigrationEncryptUploadSubmit in step 6, you can get the import log SAS URL by decrypting the Azure queue message with the "Event" value JobLogFileCreate. 您可以使用匯入記錄檔的 SAS URL 以下載記錄檔,並以步驟 6 傳回的加密金鑰解密。You can use the import log SAS URL to download the log file and decrypt it with the encryption key returned in step 6.

供重複使用的指令碼處理案例Scripting scenarios for reuse

使用下列範例指令碼。Use the following sample script. 其中包含從判斷位置和認證到提交您的套件資料以建立新移轉工作的步驟。It includes the steps from determining your locations and credentials, to submitting your package data, to creating a new migration job.

$userName = "admin@contoso.onmicrosoft.com"
$sourceFiles = "d:\data\documents"
$packagePath = "d:\data\documentPackage"
$spoPackagePath = "d:\data\documentPackageForSPO"
$targetWebUrl = "https://contoso.sharepoint.com/sites/finance"
$targetLibrary = "Documents"
$cred = Get-Credential $userName
  
New-SPOMigrationPackage -SourceFilesPath $sourceFiles -OutputPackagePath $packagePath -TargetWebUrl $targetWebUrl -TargetDocumentLibraryPath $targetLibrary -IgnoreHidden -ReplaceInvalidCharacters

在目標網站集合中查閱資料,以將套件轉換為目標套件Convert the package to a targeted one by looking up data in target site collection

$finalPackages = ConvertTo-SPOMigrationTargetedPackage -SourceFilesPath $sourceFiles -SourcePackagePath $packagePath -OutputPackagePath $spoPackagePath -TargetWebUrl $targetWebUrl -TargetDocumentLibraryPath $targetLibrary -Credentials $cred

提交套件資料以建立移轉工作Submit the package data to create the migration job

$job = Invoke-SPOMigrationEncryptUploadSubmit -SourceFilesPath $sourceFiles -SourcePackagePath $spoPackagePath -Credentials $cred -TargetWebUrl $targetWebUrl
  
This sample shows how to get the returned information of a job, which comes in the form of a GUID.
  
```powershell
$job = $jobs[0]
$job.JobId
Guid
----
779c4b3b-ec24-4705-bb58-c38f4329418c

本範例顯示如何取得 $job.ReportingQueueURi.AbosoluteUriThis sample shows how to get the $job.ReportingQueueURi.AbosoluteUri.

# To obtain the $job.ReportingQueueUri.AbsoluteUri
https://spodm1bn1m013pr.queue.core.windows.net/953pq20161005-f84b9e51038b4139a179f973e95a6d6f?sv=2014-02-14&sig=TgoUcrMk1Pz8VzkswQa7owD1n8TvLmCQFZGzyV7WV8M%3D&st=2016-10-04T07%3A00%3A00Z&se=2016-10-26T07%3A00%3A00Z&sp=rap

本範例顯示如何取得加密金鑰和傳回範例。This sample shows how to obtain the encryption key and the sample return.

$job.Encryption
EncryptionKey                                       EncryptionMethod
-----------------------                            ------------------
{34, 228, 244, 194...}                              AES256CBC

重要

佇列的所有訊息都經過加密。All messages are encrypted in the queue. 若要從 ReportingQueue 讀取,就必須持有 EncryptionKeyTo read from the ReportingQueue, you must have the EncryptionKey.

最佳作法與限制Best practices and limitations

描述Description 建議Recommendation
套件大小Package size 10 到 20 GB10-20 GB
移轉檔案共用時,使用 -ParallelImport 切換參數就能自動將大封裝分割成較小的封裝。Use the -ParallelImport switch for file share migration, which automatically splits the large package into smaller ones.
檔案大小File size
2 GB2 GB
目標大小Target size
到移轉完成之前,目標網站應保持在使用者無法存取的狀態The target site should remain non-accessible to users until migration is complete
SharePoint 限制SharePoint limits
適用於 Microsoft 365 的 SharePoint 中的服務限制Service limits in SharePoint for Microsoft 365

Azure 限制Azure limits

資源Resource 預設/限制Default/Limit
各儲存體帳戶的 TB 容量TB per storage account
500500
單一 Blob 容器、表格或佇列的最大大小。Max size of single blob container, table, or queue.
500500
每個儲存體帳戶的 Blob 容器、Blob、檔案共用、表格、佇列、實體或郵件的最大數目。Max number of blob containers, blobs, file shares, tables, queues, entities, or messages per storage account.
唯一的限制是 500 TB 的儲存體帳戶容量。The only limit is the 500-TB storage account capacity.
單一 Blob 的目標輸送量Target throughput for single blob
每秒最多 60 MB 或 500 個要求。Up to 60 MB or 500 requests per second.

Cmdlet 參考適用於 SharePoint OnlineCmdlet references are for SharePoint Online