How To Migrate A File Server To SharePoint Online Using SPMT PowerShell

Introduction 

 
In the previous blog, we have to go through the CSV creation part.
In this blog, we are going to use that file and SPMT migration PowerShell commands to migrate the file server to SharePoint Online.
 
Prerequisite
 
The SharePoint Migration Tool needs to be installed in the machine.
 
Solution
 
First, we are going to get credentials for:
  1. Import-Module Microsoft.SharePoint.MigrationTool.PowerShell    
  2. $Global:SPOUrl = "SharePoint site collection url"    
  3. $Global:UserName = "username"    
  4. $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force    
  5. $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord     
After this, we will read the CSV file.
  1. #Load CSV  
  2. $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6  
Now we will register a migration task. This needs to be done once for all migration tasks, so we will keep this out of the for loop.
  1. Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true     
We are passing the below two parameters:
  • MigrateWithoutRootFolder
    This will not migrate to the parent folder. Only items within the given path directory will be migrated. This is not mentioned in the MSDN link, but it is mentioned in the build changes document. This was included in build – 3.4.119.7

  • PreserveUserPermissionsForFileShare
    This parameter is used if you want to migrate file server permission to SharePoint online
Now we will loop through the CSV file and add migration tasks.
  1. ForEach ($item in $csvItems)    
  2. {    
  3.    Write-Host $item.c1    
  4.    Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"    
  5. }    
After this, we will start migration:
  1. Start-SPMTMigration  
The full PowerShell will look like below:
  1. Import-Module Microsoft.SharePoint.MigrationTool.PowerShell    
  2. $Global:SPOUrl = "SharePoint site collection url"      
  3. $Global:UserName = "username"      
  4. $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force      
  5. $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord      
  6. #Load CSV      
  7. $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6      
  8. Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true    
  9. ForEach ($item in $csvItems)    
  10. {    
  11.    Write-Host $item.c1    
  12.    Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"    
  13. }    
  14. Start-SPMTMigration    
References
  1. Build Release
  2. SPMT PowerShell links,
    • https://docs.microsoft.com/en-us/powershell/module/spmt/?view=spmt-ps
    • https://docs.microsoft.com/en-us/sharepointmigration/overview-spmt-ps-cmdlets