Managing Large File Uploads to OneDrive using PnP PowerShell

Loading

Uploading large files to OneDrive for Business can be challenging due to file size limits, network interruptions, and throttling. Using PnP PowerShell, we can efficiently handle large file uploads by:

Splitting large files into chunks
Resuming interrupted uploads
Managing upload performance

This guide explains step-by-step how to upload large files to OneDrive using PnP PowerShell.


Prerequisites

1️⃣ Install PnP PowerShell (if not installed)

Ensure you have the latest version of PnP PowerShell:

Install-Module -Name PnP.PowerShell -Force -AllowClobber

2️⃣ Connect to OneDrive

Before uploading files, connect to OneDrive for Business:

Connect-PnPOnline -Url "https://yourtenant-my.sharepoint.com" -Interactive

Replace "yourtenant" with your actual SharePoint tenant name.

Use Global Administrator or SharePoint Administrator credentials.


Step 1: Upload a Standard File to OneDrive

For small files (<250 MB), use:

$oneDriveFolder = "/Documents"
$filePath = "C:\Users\YourUser\Desktop\sample.pdf"

Add-PnPFile -Path $filePath -Folder $oneDriveFolder

Uploads sample.pdf to the Documents folder in OneDrive.


Step 2: Upload Large Files (Greater than 250MB) in Chunks

Why chunked uploads?

  • OneDrive limits single uploads to 250 MB using Add-PnPFile.
  • Chunked uploads handle files up to 250 GB.

Chunked Upload Script (Upload-LargeFile.ps1)

# Define variables
$oneDriveFolder = "/Documents"
$largeFilePath = "C:\Users\YourUser\Desktop\LargeFile.mp4"

# Connect to OneDrive
Connect-PnPOnline -Url "https://yourtenant-my.sharepoint.com" -Interactive

# Upload large file in chunks
Add-PnPFile -Path $largeFilePath -Folder $oneDriveFolder -ChunkSizeInMB 50

Uploads LargeFile.mp4 in 50MB chunks to OneDrive.
Prevents timeouts and supports resumable uploads.


Step 3: Automate Bulk Uploads of Large Files

For multiple large files, use:

# Define variables
$oneDriveFolder = "/Documents"
$sourceFolder = "C:\Users\YourUser\LargeFiles"

# Connect to OneDrive
Connect-PnPOnline -Url "https://yourtenant-my.sharepoint.com" -Interactive

# Upload all large files from the folder
Get-ChildItem -Path $sourceFolder -File | ForEach-Object {
$file = $_.FullName
Write-Host "Uploading: $($_.Name)" -ForegroundColor Green
Add-PnPFile -Path $file -Folder $oneDriveFolder -ChunkSizeInMB 50
}

Uploads all files in a folder to OneDrive.
Handles files larger than 250 MB seamlessly.


Step 4: Resume Interrupted Uploads

If a large file upload fails, OneDrive allows resuming it:

Add-PnPFile -Path "C:\Users\YourUser\Desktop\LargeFile.mp4" -Folder "/Documents" -ChunkSizeInMB 50

PnP PowerShell automatically resumes if the previous upload failed.


Step 5: Verify File Uploads

To confirm file uploads, retrieve the file list:

Get-PnPListItem -List "Documents" | Select-Object FileLeafRef, Modified, Editor

Displays file names, modification date, and last editor.


Step 6: Troubleshooting Large File Uploads

1️⃣ Check OneDrive Storage Limits

To check the remaining OneDrive storage:

Get-PnPStorageEntity | Where-Object { $_.Key -eq "StorageQuota" }

Ensures the upload doesn’t exceed the storage limit.


2️⃣ Verify Upload Speed

Check the upload performance with:

Measure-Command { Add-PnPFile -Path "C:\Users\YourUser\Desktop\LargeFile.mp4" -Folder "/Documents" -ChunkSizeInMB 50 }

Shows total upload time for optimization.


3️⃣ Handle Throttling Issues

If Microsoft 365 throttles the upload due to high usage:

Start-Sleep -Seconds 60
Add-PnPFile -Path "C:\Users\YourUser\Desktop\LargeFile.mp4" -Folder "/Documents" -ChunkSizeInMB 50

Waits 60 seconds before retrying.

Leave a Reply

Your email address will not be published. Required fields are marked *