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:
- 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 the CSV file.
- #Load CSV
- $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.
- 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.
- 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:
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
References
- Build Release
- 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