OneDrive storage allocation management is essential for monitoring and optimizing space usage across users in an organization. Using PnP PowerShell, you can retrieve OneDrive storage quotas, current usage, and allocated limits efficiently.
This guide explains step-by-step how to check OneDrive storage allocations using PnP PowerShell.
Step 1: Install and Update PnP PowerShell
Ensure PnP PowerShell is installed on your system. Open PowerShell as Administrator and run:
Install-Module -Name PnP.PowerShell -Force -AllowClobber
To update the module:
Update-Module -Name PnP.PowerShell
Verify the installation:
Get-Module -Name PnP.PowerShell -ListAvailable
Step 2: Connect to SharePoint Online Admin Center
Since OneDrive for Business is managed through SharePoint Online, connect to the SharePoint Online Admin Center:
$adminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-PnPOnline -Url $adminUrl -Scopes "Sites.FullControl.All" -Interactive
For App-based authentication, use:
$clientId = "your-client-id"
$tenantId = "your-tenant-id"
$clientSecret = "your-client-secret"
Connect-PnPOnline -Url $adminUrl -ClientId $clientId -ClientSecret $clientSecret -Tenant $tenantId
Step 3: Retrieve OneDrive Storage Allocations
Run the following command to list all OneDrive sites and their storage details:
$oneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites | Where-Object { $_.Url -like "*-my.sharepoint.com/personal/*" }
$oneDriveSites | Select-Object Url, Owner, StorageUsageCurrent, StorageQuota | Format-Table -AutoSize
This command displays:
✔ OneDrive Site URL
✔ Storage Used (MB)
✔ Total Storage Quota (MB)
✔ Site Owner
Step 4: Export Storage Data to CSV
To save the storage details in a CSV file for further analysis:
$reportPath = "C:\Reports\OneDrive_Storage_Report.csv"
$oneDriveSites | Select-Object Url, Owner, StorageUsageCurrent, StorageQuota | Export-Csv -Path $reportPath -NoTypeInformation
Write-Host "OneDrive Storage Report saved to $reportPath"
Step 5: Automate Storage Monitoring
To automate this process, schedule the script using Task Scheduler.
1. Open Task Scheduler
- Click Start, search for Task Scheduler, and open it.
- Click Create Basic Task.
- Name it “OneDrive Storage Report”.
2. Set Trigger
- Choose Daily or any required frequency.
- Set the execution time.
3. Set Action
- Select Start a Program.
- In Program/Script, enter:
powershell.exe
- In Arguments, enter:
-File "C:\Scripts\OneDriveStorageReport.ps1"
- Click Finish.
This will automate OneDrive storage reporting.
Step 6: Review the Report
To check the generated report:
Import-Csv -Path "C:\Reports\OneDrive_Storage_Report.csv" | Format-Table -AutoSize