Using PowerShell scripts for SharePoint Migration gives you better control and flexibility. In this article, we will look at 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.
We will also look at a scenario where you can use a PowerShell Script to add a SP On-Premises task to start a migration.
But before we get to that, let us look at the new cmdlets
Let us explore some of the PowerShell cmdlets that play an important role in SharePoint Migration
This cmdlet can be used to create and then initialize a SharePoint migration session. In case, there is 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.
If you want to add a new migration task to the registered migration session, then this cmdlet can be used. You can add three different types of tasks: File share task, SharePoint task, and JSON defined task.
You can use this cmdlet if you want to remove an existing migration task from the registered migration.
This cmdlet will start the registered SPMT migration.
This can be used to return the object of the current session. It will include the status of current tasks and current session level settings.
This cmdlet will cancel the current migration.
If you start the migration in NoShow mode, running the Show-SPMTMigration cmdlet displays the task ID, data source location, target location, and migration status in the console.
You can use this cmdlet to delete the migration session.
Here is a custom PowerShell script to add a SharePoint On-Premises task and start SharePoint migration.
#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
At Evolvous, you get tailored solutions for SharePoint migration. Discover how our specialist SharePoint migration specialists help you with SharePoint migration from On-premises to Online, or from legacy systems.