Bulk Assigning OneDrive Quotas using PnP PowerShell

Loading

Managing OneDrive storage quotas efficiently is crucial for organizations using Microsoft 365. By leveraging PnP PowerShell, administrators can automate the process of assigning and updating storage limits for multiple users at once, eliminating the need for manual adjustments in the Microsoft 365 Admin Center.

Why use PnP PowerShell for OneDrive Quotas?

  • Bulk updates for multiple users
  • Automation reduces manual errors
  • Ensures compliance with organizational storage policies

Prerequisites

Before executing PnP PowerShell commands, ensure the following:

1️⃣ Install PnP PowerShell (if not installed)

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

2️⃣ Connect to SharePoint Online Admin Center

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

3️⃣ Required Permissions

You must have:
SharePoint Administrator or Global Administrator role
OneDrive for Business Admin access


Step 1: Retrieve Current OneDrive Quotas

To get the storage quota of all OneDrive sites:

Get-PnPTenantSite -IncludeOneDriveSites | Select Title, Url, StorageQuota, StorageQuotaWarningLevel

Lists all OneDrive storage quotas and warning levels.


Step 2: Bulk Assign OneDrive Quotas from a CSV File

Prepare a CSV File (OneDriveQuotas.csv) with the following format:

UserPrincipalName,StorageQuota,StorageQuotaWarningLevel
user1@yourtenant.com,500000,450000
user2@yourtenant.com,1024000,900000
user3@yourtenant.com,2048000,1800000

UserPrincipalName → OneDrive Owner
StorageQuota → Total storage in MB (500000 MB = 500 GB)
StorageQuotaWarningLevel → Warning threshold (MB)


Run the PowerShell Script to Apply Storage Quotas

# Load CSV file
$users = Import-Csv "C:\Path\To\OneDriveQuotas.csv"

foreach ($user in $users) {
$OneDriveUrl = "https://yourtenant-my.sharepoint.com/personal/" + ($user.UserPrincipalName -replace "@", "_") + "/"

# Apply Storage Quota
Set-PnPTenantSite -Url $OneDriveUrl -StorageQuota $user.StorageQuota -StorageQuotaWarningLevel $user.StorageQuotaWarningLevel

Write-Host "Updated quota for $($user.UserPrincipalName)"
}

Reads OneDrive URLs from the CSV
Updates Storage Quotas and Warning Levels


Step 3: Verify Updated Quotas

To verify the updated OneDrive quotas, run:

Get-PnPTenantSite -IncludeOneDriveSites | Select Title, Url, StorageQuota, StorageQuotaWarningLevel

Confirms whether quotas were successfully updated.


Step 4: Automate Quota Updates with a Scheduled Task

To automate quota assignments weekly, save the script as Set-OneDriveQuotas.ps1 and use Task Scheduler:

# Define CSV File Path
$csvPath = "C:\Path\To\OneDriveQuotas.csv"

# Connect to SharePoint
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Credentials (Get-Credential)

# Load CSV file
$users = Import-Csv $csvPath

foreach ($user in $users) {
$OneDriveUrl = "https://yourtenant-my.sharepoint.com/personal/" + ($user.UserPrincipalName -replace "@", "_") + "/"
Set-PnPTenantSite -Url $OneDriveUrl -StorageQuota $user.StorageQuota -StorageQuotaWarningLevel $user.StorageQuotaWarningLevel
Write-Host "Updated quota for $($user.UserPrincipalName)"
}

Automates quota management on a schedule


Troubleshooting Issues

1️⃣ Error: “Access Denied”

Ensure your account has SharePoint Admin permissions
Try running PowerShell as Administrator

2️⃣ Quotas Not Updating?

Check the OneDrive URL format
Verify that the CSV file contains correct values

3️⃣ PowerShell Module Not Found?

Update PnP PowerShell:

Update-Module PnP.PowerShell

Leave a Reply

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