Sunday, 6 December 2020

File server migration to SharePoint online using SPMT PowerShell Part 2

In previous blog we have go through the csv creation part. You can find it on below link:

In this blog, we are going to use that file and SPMT migration PowerShell commands to migrate file server to SharePoint online.

Prerequisite

SharePoint Migration Tool needs to be installed in the machine

Solution

First, we are going to get credentials for

 Import-Module Microsoft.SharePoint.MigrationTool.PowerShell  
 $Global:SPOUrl = "SharePoint site collection url"  
 $Global:UserName = "username"  
 $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force  
 $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord  

 

After this we will read csv file

 #Load CSV  
 $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6  

 

Now we will register migration task. This needs to be done once for all migration task. So we will keep this out of for loop

 Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true  

 

We are passing below two parameters

  1. MigrateWithoutRootFolder – This will not migrate parent folder. Only items withing 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

  2. PreserveUserPermissionsForFileShare – This parameter is used if you want to migrate file server permission to SharePoint online

 

Now we will loop through csv file and add migration task.

 ForEach ($item in $csvItems)  
 {       
   Write-Host $item.c1  
   Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"  
 }  

 

After this we will start migration

 Start-SPMTMigration  

 

The full PowerShell will look like below:

 Import-Module Microsoft.SharePoint.MigrationTool.PowerShell  
 $Global:SPOUrl = "SharePoint site collection url"  
 $Global:UserName = "username"  
 $Global:PassWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force  
 $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord  
 #Load CSV  
 $csvItems = import-csv "C:\Migration\migrationscript.csv" -Header c1,c2,c3,c4,c5,c6  
 Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force -MigrateWithoutRootFolder -PreserveUserPermissionsForFileShare $true  
 ForEach ($item in $csvItems)  
 {  
   Write-Host $item.c1  
   Add-SPMTTask -FileShareSource $item.c1 -TargetSiteUrl $item.c4 -TargetList $item.c5 -TargetListRelativePath "/"  
 }  
 Start-SPMTMigration  

 

Reference

No comments:

Post a comment