How To Migrate Files From Folder Share To SharePoint Online Using PowerShell

SharePoint Migration Tool (SPMT)

This tool allows you to migrate lists or files from your SharePoint on-premises document libraries or from your on-premises file shares and easily move them to either SharePoint or OneDrive in Office 365. It is available to Office 365 users.

In the latest version, Microsoft has introduced PowerShell cmdlets to perform migration that has all features of the SharePoint Migration Tool (SPMT).

Click here to download the SPMT latest version 2.1.100.0 (currently in open beta). The PowerShell .dll's will be copied to %userprofile%\Documents\WindowsPowerShell\Modules location.

Copy the below script and paste it in a Notepad. Save the file as SPMTMigration.ps1.

  1. # Module Location  
  2. $Global:ModulePath = "C:\Users\vijai\Documents\WindowsPowerShell\Modules\Microsoft.SharePoint.MigrationTool.PowerShell"  
  3.  
  4. # File Share Source Location  
  5. $Global:FileShareSource = "C:\Users\vijai\Desktop\DeploymentAutomation"  
  6.  
  7. # SharePoint Online Target Site Details  
  8. $Global:SPOUrl = "https://c986.sharepoint.com/sites/dev"  
  9. $Global:SPOCredential = Get-Credential  
  10. $Global:ListName="Documents"  
  11.  
  12. # Import SPMT Module  
  13. Import-Module ($modulePath + "\Microsoft.SharePoint.MigrationTool.PowerShell.psd1")  
  14.  
  15. # Create a migration session and initialize it  
  16. Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force  
  17.  
  18. # Add a new migration task to the registered migration session  
  19. Add-SPMTTask -FileShareSource $Global:FileshareSource -TargetSiteUrl $Global:SPOUrl -TargetList $Global:ListName  
  20.  
  21. # Start the registered SPMT migration  
  22. Start-SPMTMigration  
  23.  
  24. # Cancel the current migration session  
  25. Stop-SPMTMigration   
  26.  
  27. # Remove the SPMT migration session created  
  28. Unregister-SPMTMigration  

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

 folderlocation – where the SPMTMigration.ps1 file is saved

Run the following command

  1. >.\SPMTMigration.ps1  

 Enter the SharePoint Online site credentials in the pop-up and enter OK. After a few minutes, the files from folder share will be migrated to SharePoint Online site.

 

Reference - https://docs.microsoft.com/en-us/powershell/module/spmt/?view=spmt-ps

Thus, in this blog, you saw how to migrate files from Folder Share to SharePoint Online using PowerShell based on the SharePoint Migration Tool (SPMT) migration engine.