When migrating content to SharePoint Online, performing a full migration initially is common. However, to keep content up to date, you need incremental migrations—which only transfer newly added or modified files since the last migration.
Using PnP PowerShell, you can:
✔ Migrate only new or updated files
✔ Reduce migration time and avoid duplicate uploads
✔ Schedule automated incremental migrations
This guide covers the step-by-step process.
Step 1: Install and Connect PnP PowerShell
Ensure you have PnP PowerShell installed:
Install-Module -Name PnP.PowerShell -Force -AllowClobber
Update-Module -Name PnP.PowerShell
Connect to SharePoint Online:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
Step 2: Perform an Initial Migration
If you haven’t already performed the first migration, migrate all files:
$sourcePath = "C:\LocalFolder"
$destinationLibrary = "Shared Documents"
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/YourSite" -Interactive
# Migrate all files from local folder to SharePoint
Add-PnPFile -Path $sourcePath -Folder $destinationLibrary -Connection $conn
Write-Host "Initial migration completed."
✔ Ensures all files are uploaded to SharePoint.
Step 3: Identify Files for Incremental Migration
To check for new or modified files, compare last modified timestamps:
$sourcePath = "C:\LocalFolder"
$destinationLibrary = "Shared Documents"
# Get the latest modified file from SharePoint
$latestFile = Get-PnPListItem -List $destinationLibrary | Sort-Object -Property Modified -Descending | Select-Object -First 1
$lastMigrationDate = $latestFile.FieldValues["Modified"]
Write-Host "Last Migration Date: $lastMigrationDate"
# Get files modified after the last migration
$incrementalFiles = Get-ChildItem -Path $sourcePath -Recurse | Where-Object { $_.LastWriteTime -gt $lastMigrationDate }
Write-Host "Files to be migrated:"
$incrementalFiles | ForEach-Object { Write-Host $_.FullName }
✔ Identifies only new or modified files for migration.
Step 4: Perform Incremental Migration
Upload only the identified files to SharePoint:
foreach ($file in $incrementalFiles) {
$destinationFilePath = $file.FullName.Replace($sourcePath, "").TrimStart("\")
Add-PnPFile -Path $file.FullName -Folder $destinationLibrary/$destinationFilePath
Write-Host "Uploaded: $($file.FullName)"
}
Write-Host "Incremental migration completed."
✔ Ensures only new or updated files are migrated.
Step 5: Automate Incremental Migrations
To run the migration automatically at scheduled intervals:
- Save the script as
IncrementalMigration.ps1
. - Open Task Scheduler → Create Basic Task.
- Set Trigger → Daily, Weekly, or at a Custom Interval.
- Set Action → Start a Program.
- Use the following PowerShell command:
-ExecutionPolicy Bypass -File "C:\Scripts\IncrementalMigration.ps1"
✔ Ensures continuous synchronization of content.