1. Introduction
Synchronizing SharePoint Document Libraries with OneDrive ensures seamless access to files across devices, enabling offline work and automatic updates. PnP PowerShell helps automate the sync process, making it efficient and error-free.
With this guide, you’ll learn how to:
Sync a SharePoint Document Library with OneDrive
Automate the synchronization process
Handle large files and ensure data integrity
2. Prerequisites
Before starting, ensure:
- You have PnP PowerShell installed. If not, install it using:
Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force
- You have OneDrive for Business installed and configured on your system.
- You have SharePoint Site Owner or Administrator permissions.
- You know the URL of the SharePoint document library you want to sync.
3. Connecting to SharePoint Online
To interact with SharePoint, establish a secure connection.
Step 1: Connect to SharePoint
$SiteURL = "https://yourtenant.sharepoint.com/sites/YourSite"
Connect-PnPOnline -Url $SiteURL -Interactive
- Replace
"yourtenant"
with your SharePoint tenant name. - Replace
"YourSite"
with your actual SharePoint site name.
This command prompts a login window for authentication.
4. Understanding OneDrive and SharePoint Sync
How SharePoint Syncs with OneDrive
- Manual Sync: Users can sync SharePoint libraries via OneDrive manually.
- PnP PowerShell Sync: Automates the sync process for efficiency.
Common Use Cases
✔️ Backup files from SharePoint to OneDrive
✔️ Enable offline access to SharePoint libraries
✔️ Ensure all files are up-to-date across multiple devices
5. Syncing SharePoint Libraries with OneDrive
To sync a SharePoint document library with OneDrive:
Step 1: Get the Document Library URL
Run the following command to list document libraries:
Get-PnPList -Web $SiteURL | Where-Object {$_.BaseType -eq "DocumentLibrary"} | Select-Object Title,Url
This displays available document libraries and their URLs.
Step 2: Generate OneDrive Sync URL
Use the following format:
$LibraryURL = "https://yourtenant.sharepoint.com/sites/YourSite/Shared Documents"
$OneDriveSyncURL = "odopen://sync?siteId=$SiteURL&webId=$LibraryURL"
- This creates the OneDrive Sync URL, which triggers OneDrive to sync the library.
Step 3: Trigger OneDrive Sync
Start-Process $OneDriveSyncURL
This command launches OneDrive and initiates the sync.
6. Automating Synchronization with PowerShell
To ensure continuous sync, schedule the process with Task Scheduler.
Step 1: Create a PowerShell Script
Save the following script as Sync-SharePointToOneDrive.ps1
:
$SiteURL = "https://yourtenant.sharepoint.com/sites/YourSite"
$LibraryURL = "https://yourtenant.sharepoint.com/sites/YourSite/Shared Documents"
$OneDriveSyncURL = "odopen://sync?siteId=$SiteURL&webId=$LibraryURL"
# Connect to SharePoint
Connect-PnPOnline -Url $SiteURL -Interactive
# Start OneDrive Sync
Start-Process $OneDriveSyncURL
Write-Host "Sync initiated successfully!"
Step 2: Schedule Sync Task
- Open Task Scheduler.
- Click Create Basic Task.
- Choose a Trigger (daily, weekly, or at system startup).
- Select Action > Start a Program.
- Set Program/Script to
powershell.exe
. - In Add Arguments, enter:
-File "C:\Path\To\Sync-SharePointToOneDrive.ps1"
- Click Finish and enable the task.
This ensures automated synchronization without manual intervention.
7. Handling Large Libraries and Errors
Large SharePoint libraries may cause sync delays or failures. Use these strategies:
Check OneDrive Limits
- OneDrive supports up to 300,000 files per library.
- Individual file size must not exceed 250GB.
Resolve Sync Issues
If sync issues arise, restart the OneDrive client:
Stop-Process -Name "OneDrive" -Force
Start-Process "C:\Program Files\Microsoft OneDrive\OneDrive.exe"
8. Monitoring Sync Status
Check OneDrive Sync Status via PowerShell
Get-Process -Name "OneDrive"
If OneDrive is running, it returns process details.
Verify Sync Progress in OneDrive
- Open OneDrive from the taskbar.
- Click Settings > View Sync Problems to resolve issues.