Listing All OneDrive Sites in a Tenant using PnP PowerShell

Loading

OneDrive for Business is integrated with SharePoint Online, and every user in a Microsoft 365 tenant has a personal OneDrive site. As an administrator, you may need to list all OneDrive sites within your organization to monitor storage usage, apply security policies, or manage access.

In this guide, we will cover:
Connecting to SharePoint Online using PnP PowerShell
Retrieving a list of all OneDrive sites
Exporting the OneDrive site list to a CSV file


Step 1: Install PnP PowerShell

If you haven’t installed PnP PowerShell, install it using:

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

Once installed, import the module:

Import-Module PnP.PowerShell

PnP PowerShell is now ready!


Step 2: Connect to SharePoint Online

To retrieve all OneDrive sites, connect to SharePoint Online as an administrator:

$tenantAdminUrl = "https://yourtenant-admin.sharepoint.com"

Connect-PnPOnline -Url $tenantAdminUrl -Interactive

🔹 Replace “yourtenant” with your actual Microsoft 365 tenant name.
🔹 A login prompt will appear—sign in as a Global Administrator or SharePoint Admin.

Successfully connected to SharePoint Online!


Step 3: List All OneDrive Sites in the Tenant

To retrieve all OneDrive sites, use the following command:

Get-PnPTenantSite -IncludeOneDriveSites

This command will return:

  • URL of each user’s OneDrive site
  • Storage quota details
  • Site owner information

OneDrive sites retrieved successfully!


Step 4: Export OneDrive Sites to a CSV File

To save the OneDrive site list as a CSV file:

$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites
$OneDriveSites | Select-Object Url, Owner, StorageUsageCurrent, StorageQuota | Export-Csv -Path "C:\OneDriveSites.csv" -NoTypeInformation

🔹 This exports site details (URL, owner, storage usage, and quota) into a CSV file.
🔹 The file will be saved at C:\OneDriveSites.csv.

OneDrive sites exported to CSV!


Step 5: Disconnect from SharePoint Online

Once done, disconnect the session:

Disconnect-PnPOnline

Disconnected successfully!

Leave a Reply

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