How to Generate a Report About OneDrive for Business Storage

Now Much Easier to Find OneDrive for Business Sites with PowerShell

A couple of years ago, retrieving information about OneDrive for Business sites with PowerShell usually involved some gyrations. Then Microsoft updated the Get-SPOSite cmdlet with the IncludePersonalSite switch and things became easier. For instance, a reader asked if it was possible to generate a report listing all the OneDrive for Business sites in a tenant with the storage allocated and used for each site.

No problem, we thought, as we scanned the internet to see if people had already solved the problem. As it happens, several example scripts are available, but we ended up writing our own because it was possible to simplify the code . We also store the output in a CSV file as it’s a very flexible format for reporting or further analysis (like importing into Power BI).

PowerShell Report for OneDrive Storage

You need to connect to SharePoint Online in a PowerShell session with an admin account. The connection process imports the SharePoint cmdlets from the module. Once a connection is made, you can retrieve the storage data. The basic steps are:

  • Create an array of the OneDrive for Business sites in the tenant.
  • Select useful properties for each site.
  • Calculate the total OneDrive storage used for the tenant.
  • Write the information for each OneDrive site into a PowerShell list.
  • Write the list out as a CSV file.

Here’s the code:

# Get a list of OneDrive for Business sites in the tenant sorted by the biggest consumer of quota
Write-Host "Finding OneDrive sites..."
[array]$ODFBSites = Get-SPOSite -IncludePersonalSite $True -Limit All -Filter "Url -like ''" | Select Owner, Title, URL, StorageQuota, StorageUsageCurrent | Sort StorageUsageCurrent -Descending
If (!($ODFBSites)) { Write-Host "No OneDrive sites found (surprisingly...)" ; break }
# Calculate total used
$TotalODFBGBUsed = [Math]::Round(($ODFBSites.StorageUsageCurrent | Measure-Object -Sum).Sum /1024,2)
# Create list to store report data
$Report = [System.Collections.Generic.List[Object]]::new()
# Store information for each OneDrive site
ForEach ($Site in $ODFBSites) {
      $ReportLine   = [PSCustomObject]@{
        Owner       = $Site.Title
        Email       = $Site.Owner
        URL         = $Site.URL
        QuotaGB     = [Math]::Round($Site.StorageQuota/1024,2) 
        UsedGB      = [Math]::Round($Site.StorageUsageCurrent/1024,4)
        PercentUsed = [Math]::Round(($Site.StorageUsageCurrent/$Site.StorageQuota * 100),4) }
      $Report.Add($ReportLine) }
$Report | Export-CSV -NoTypeInformation c:\temp\OneDriveSiteConsumption.CSV
# You don't have to do this, but it's useful to view the data via Out-GridView
$Report | Sort UsedGB -Descending | Out-GridView
Write-Host "Current OneDrive for Business storage consumption is" $TotalODFBGBUsed "GB. Report is in C:\temp\OneDriveSiteConsumption.CSV"

Figure 1 shows an example of the CSV file generated by the script. Because the information is in a CSV file, you can sort and organize it in whatever way makes sense for you. Some organizations like to grab information like this and store it in a repository to track the growth in storage consumption over time.

CSV file listing the storage consumed by OneDrive for Business sites
Figure 1: CSV file listing the storage consumed by OneDrive for Business sites

The public health warning is that we’ve not tested the script on very large tenants. It might take some time to run in those conditions, in which case you could break up processing. For instance, you could filter for sites starting with each letter of the alphabet and then combine the results for each letter into a single file.

Need more information about managing OneDrive for Business? Because the same general approach can usually be taken for both SharePoint Online and OneDrive for Business, we cover that topic in the chapter that deals with SharePoint Online management in the Office 365 for IT Pros eBook.

5 Replies to “How to Generate a Report About OneDrive for Business Storage”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.