Get OneDrive Storage Metrics Report with PowerShell

Do you know how much OneDrive storage your users are using? Probably not, and in most cases, it also doesn’t really matter. They get 1TB of storage with most Microsoft 365 plans and the data is only synced with their own devices.

But when you are planning your Microsoft 365 backup solution and need to calculate the required storage size then it can be useful to create a OneDrive storage size report. Also when you are planning to downscale your Microsoft 365 license you might need to check how much storage your users are using.

I created a PowerShell script that will gather the OneDrive usages from all your users with the storage quota, OneDrive status, and last modified file date.

Get OneDrive Storage Metrics

There are a couple of options to get the OneDrive storage metrics. From the user account you can quickly open the metrics from the OneDrive client:

  1. Right-click on the OneDrive client icon
  2. Choose Manage storage
OneDrive Storage Metrics

In the top-right corner, you can see how much storage you are using.

Show storage metrics from the Admin Center

You can also get the OneDrive storage metrics from the Microsoft 365 Admin center. In the admin center, click on:

  1. Active users
  2. Select a user
  3. Click on the OneDrive tab
OneDrive Storage Usage

Use the built-in report in Microsoft 365

In the Microsoft 365 Admin center, you will also find a lot of built-in reports that you can use. One of them is the OneDrive Usage report. By default, you won’t see the display name in the report. They are concealed.

So we first have to enable identifiable information before we can use the report.

  1. In the Admin Center, open Settings > Org Settings > Services
  2. Click on Reports
  3. Disable “Display concealed user, group, and site names in all reports
  4. Click Save

To view the OneDrive usage report we need to go to:

  1. Reports > Usage
  2. Under OneDrive Files, click View More
  3. Scroll a bit down the view the port.
Onedrive storage metrics report

You can export this information to a CSV file.

Using PowerShell to export OneDrive usage

You can also use PowerShell to generate a report with the OneDrive usage. We are going to use the PowerShell PnP Online module for this. Make sure you have installed it before you continue.

With PnP Online we can get all the OneDrive sites with the cmdlet below. We use a filter to select all SharePoint sites on their URL to match the personal sites only.

Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'" -Detailed

The complete function to extra only the data we need and add it into a PSCustomObject:

Function Get-OneDriveStats {
  <#
    .SYNOPSIS
        Get the mailbox size and quota
  #>
  process {
    $oneDrives = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'" -Detailed | Select Title,Owner,StorageQuota,StorageQuotaWarningLevel,StorageUsageCurrent,LastContentModifiedDate,Status
    $i = 0

    $oneDrives | ForEach {
  
      [pscustomobject]@{
        "Display Name" = $_.Title
        "Owner" = $_.Owner
        "Onedrive Size (Gb)" = ConvertTo-Gb -size $_.StorageUsageCurrent
        "Storage Warning Quota (Gb)" = ConvertTo-Gb -size $_.StorageQuotaWarningLevel
        "Storage Quota (Gb)" = ConvertTo-Gb -size $_.StorageQuota
        "Last Used Date" = $_.LastContentModifiedDate
        "Status" = $_.Status
      }

      $currentUser = $_.Title
      Write-Progress -Activity "Collecting OneDrive Sizes" -Status "Current Count: $i" -PercentComplete (($i / $oneDrives.Count) * 100) -CurrentOperation "Processing OneDrive: $currentUser"
      $i++;
    }
  }
}

As you can see I convert all the data to Gb, using the function ConvertTo-Gb that I have also used in this Mailboxes size report script.

You can download the complete script here from my Github repository. To run the script you will need to supply your SharePoint admin URL and optionally the location to store the CSV file:

Get-OneDriveSizeReport.ps1 url "https://contoso-admin.sharepoint.com" -path c:\temp\reportoneDrive.csv

Wrapping Up

The built-in report in the Microsoft 365 Admin center is for most use cases more than enough. But with PowerShell, you can create one complete report with the mailboxes sizes and OneDrive storage size for example.

If you have any questions just drop a comment below.

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

Leave a Comment

0 Shares
Tweet
Pin
Share
Share