Identify Orphaned and Inactive OneDrive Accounts via Graph Usage Reports

Prev Next

Cross-reference OneDrive usage data with Entra ID to surface ex-employee drives, inactive accounts, and large drives ready for cleanup, transfer, or retention review.

Complexity: Intermediate. Impact: storage-reclamation + offboarding + compliance + cost-optimization + tenant-hygiene.

Why use this workflow

OneDrive for Business storage grows quietly. When employees leave, are disabled in Entra ID, or stop using OneDrive, their personal sites often remain in place, consuming storage, holding potentially sensitive data, and creating retention and compliance risk.

This workflow identifies three categories of OneDrive accounts that need attention:

  • Orphaned drives: the owner's Entra ID account is disabled or no longer exists in the directory (typical for ex-employees).
  • Inactive drives: the owner is still active, but the OneDrive has had no file activity for 90 or more days.
  • Large drives: drives exceeding a configurable size threshold (for example, 10 GB or 50 GB) that may warrant review regardless of activity.

Run this monthly or quarterly as part of routine tenant hygiene, or before a storage purchase decision. It is useful after bulk offboardings, M&A events, or license true-ups.

Expected outcomes

  • A tenant-wide inventory of every OneDrive with owner UPN, display name, storage used, last activity date, and Entra ID account status.
  • A prioritized list of orphaned and disabled-owner drives sorted by storage footprint.
  • A list of inactive drives belonging to active users who may need follow-up, or whose data may be archivable.
  • A list of large drives (above your configurable threshold) for storage capacity review.
  • A CSV report (OneDrive_Cleanup_Analysis.csv) you can share with stakeholders or feed into a follow-on transfer or deletion workflow.

Risks and considerations

  • Usage report anonymization. By default, Microsoft 365 anonymizes user-level reports. You must turn off Display concealed user, group, and site names in all reports in the Microsoft 365 admin center for Owner Principal Name and Site URL to populate. Turn it back on after your analysis if policy requires it.
  • Reporting latency. Last Activity Date and Storage Used lag real activity. Do not act on same-day data.
  • Orphaned does not mean deletable. A disabled account may be on legal hold, in a retention policy, or pending a manager-led data transfer. Check eDiscovery holds and your offboarding procedure before removing a OneDrive.
  • Deleted-user retention period. When an Entra ID user is deleted, their OneDrive enters a retention period. Surface these drives before the retention window closes so data owners can claim content.
  • Data transfer first. For ex-employee drives with business content, reassign ownership to the manager in the SharePoint admin center before any cleanup action, so teams that need the files keep access.
  • Shared files break on deletion. If an orphaned OneDrive contains files shared with active users, deleting the drive breaks those links. Inventory external sharing before acting.
  • Report permissions are sensitive. Reports.Read.All exposes usage data for every user. Scope app registrations tightly and rotate secrets regularly.

Required permissions

PermissionWhy it's needed
Reports.Read.AllRequired to call getOneDriveUsageAccountDetail and retrieve per-user storage and activity data.
User.Read.AllRequired to enumerate Entra ID users and check accountEnabled status for orphan detection.
Sites.Read.AllOptional: required if you want to enrich the report with site-level metadata (for example, last modified, owner SPO properties).
Directory.Read.AllAlternative to User.Read.All when the app also needs group or directory object data for the cross-reference.

Ask Dex

Paste the prompt into a Dex conversation.

Prompt for IT admins

Analyze OneDrive usage across the tenant. Pull the last 90 days of detailed OneDrive usage data, cross-reference owner UPNs against Entra ID, and produce a report of orphaned drives (disabled or deleted owners), inactive drives (no activity in 90+ days), and large drives (over {threshold_gb} GB). Sort by storage footprint and output a CSV of cleanup candidates with site URLs.

Manual steps (admin center)

Use this approach for a one-off report when you do not have scripting access.

Step 1: Temporarily turn off report anonymization

  1. Sign in to the Microsoft 365 admin center as a Global Administrator.
  2. Go to Settings > Org settings > Services > Reports.
  3. Clear Display concealed user, group, and site names in all reports.
  4. Click Save.

Step 2: Export the OneDrive usage detail report

  1. Go to Reports > Usage > OneDrive > Usage.
  2. Set the date range to Last 90 days.
  3. Click the Export icon in the top-right and save the CSV.

Step 3: Export the user directory

  1. Go to Users > Active users.
  2. Click Export users and save the CSV. This file includes Display Name, User Principal Name, and Block Sign-in columns.
  3. Go to Users > Deleted users and note any UPNs still within the soft-delete window.

Step 4: Cross-reference in Excel

  1. Open the OneDrive usage CSV and add a column named Account Status.
  2. Use VLOOKUP or XLOOKUP against the Active users file, matching on User Principal Name and returning the Block Sign-in value.
  3. Classify each row: missing from the lookup means Orphaned, Block Sign-in = Yes means Disabled, and anything else is Active.
  4. Add a Days Since Last Activity column: =TODAY()-[@[Last Activity Date]].
  5. Apply an AutoFilter: sort descending by Storage Used (Byte) and filter Account Status to Orphaned and Disabled.

Step 5: Review in the SharePoint admin center

  1. For each high-priority orphaned drive, open the SharePoint admin center.
  2. Go to Sites > Active sites and filter for OneDrive.
  3. Click the site URL from your CSV and review secondary admins, sharing links, and storage breakdown.
  4. If action is needed, use Permissions > Manage site admins to grant yourself or the ex-employee's manager access before any transfer or deletion.

Step 6: Turn anonymization back on

Return to the setting in Step 1 and select the anonymization option again if your organization requires it.

Microsoft Graph API

The analysis is a two-call join: pull the OneDrive usage detail report, then pull the Entra ID user directory and cross-reference on UPN.

1. Fetch the OneDrive usage detail report

The report endpoint returns CSV by default. The $format=application/json query parameter is not supported here, and requesting JSON returns HTTP 400.

GET https://graph.microsoft.com/v1.0/reports/getOneDriveUsageAccountDetail(period='D90')
Authorization: Bearer {token}
Accept: text/csv

Supported period values: D7, D30, D90, D180.

Sample response (CSV)

Report Refresh Date,Site Id,Site URL,Owner Display Name,Is Deleted,
Last Activity Date,File Count,Active File Count,Storage Used (Byte),
Storage Allocated (Byte),Owner Principal Name,Report Period
2026-03-09,002a9740-...,https://contoso-my.sharepoint.com/personal/jdoe_contoso_com/Documents,
Jane Doe,False,2026-03-09,2741,276,2119011051,1099511627776,jdoe@contoso.com,90

2. Enumerate Entra ID users with pagination

GET https://graph.microsoft.com/v1.0/users?$select=userPrincipalName,accountEnabled,displayName,id&$top=999
Authorization: Bearer {token}

Follow @odata.nextLink until all pages are consumed.

Sample response

{
  "value": [
    {
      "userPrincipalName": "jdoe@contoso.com",
      "accountEnabled": true,
      "displayName": "Jane Doe",
      "id": "8a7b..."
    }
  ],
  "@odata.nextLink": "https://graph.microsoft.com/v1.0/users?$skiptoken=..."
}

3. Classification logic

For each OneDrive row, look up Owner Principal Name (lowercased) in the user map:

  • Not found: Orphaned (user deleted).
  • Found, accountEnabled = false: Disabled (likely an ex-employee).
  • Found, accountEnabled = true, Last Activity Date more than 90 days ago: Inactive.
  • Storage Used (Byte) / 1073741824 greater than your threshold: Large (flag independently).

Throttling and error handling

  • The reports endpoint is throttled separately from the main Graph surface. Respect Retry-After headers on HTTP 429.
  • The users endpoint supports ConsistencyLevel: eventual with $count=true for advanced queries on large tenants.
  • Owner Principal Name is empty (anonymized) if the tenant's concealment setting is on. Verify the setting before you run the analysis.

PowerShell

Prerequisites

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Reports.Read.All", "User.Read.All"

Approach

  1. Call Get-MgReportOneDriveUsageAccountDetail (which wraps the Graph report endpoint) and load the CSV into memory.
  2. Page through Get-MgUser to build a hash table keyed on lowercase UPN.
  3. Walk every OneDrive row, tag it Orphaned, Disabled, Inactive, or Active, and calculate GB usage.
  4. Export three CSVs: orphaned, inactive, and a combined cleanup candidates list.
  5. Print a console summary with the top reclamation targets.

Tuning thresholds

  • Inactive days threshold: use 90 as a starting point. Raise it for users who are active quarterly, or lower it for more aggressive cleanup.
  • Large drive threshold in GB: choose a value that fits your tenant, such as 10, 50, or 100.
  • Report period: D7, D30, D90, or D180.

This approach only reads data, so it is safe to run on a schedule.