PowerShell Script to Add a SharePoint On-Premises Task

Author Details

avatar-teacher

Evolvous

We are a team of tech enthusiast and this section is where we love to share our experience and our knowledge. We try our best to help you understand technical topics by giving you live instances of how-to’s, guides, tips, FAQ’s and troubleshoots.

If you like it or have questions, do share your feedback in the comments section below.

How to Use PowerShell Script to Add a SharePoint On-Premises Task and Start SharePoint Migration?

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 

PowerShell cmdlets for SharePoint Migration 

Let us explore some of the PowerShell cmdlets that play an important role in SharePoint Migration 

Register-SPMTMigration 

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. 

Adding a Migration Task 

Add-SPMTTask 

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. 

Remove a Task

Remove-SPMTTask 

You can use this cmdlet if you want to remove an existing migration task from the registered migration. 

Starting Migration 

Start-SPMTMigration 

This cmdlet will start the registered SPMT migration. 

Return the Object of Current Session 

Get-SPMTMigration 

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.  

Stop Your Current Migration 

Stop-SPMTMigration 

This cmdlet will cancel the current migration. 

Show Your Migration Status Details  

Show-SPMTMigration 

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.  

Remove the migration session 

Unregister-SPMTMigration 

You can use this cmdlet to delete the migration session. 

PowerShell Script to Add a SharePoint On-Premises Task and Start SharePoint Migration 

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 

Get Complete Support for Custom SharePoint Migration  

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. 

Our SharePoint Migration Solutions