SharePoint storage reaching the red line is terrible. Users will start complaining they cannot store more documents on their team sites. Administrators must ensure SharePoint site owners are notified of their siteโs storage usage, so they can perform housekeeping as needed.
Weโll discover in this post how to generate a SharePoint storage report using PowerShell.
Now check if the module is available by running the command:
Get-Module PnP.PowerShell -ListAvailable
Retrieve the SharePoint Site Collections
Retrieving the site collections is the first step to generating the SharePoint storage report. The specific cmdlet to get a site collectionโs information is the Get-PnpTenantSite. Depending on the type of sites you want to retrieve, you can apply filters and switches to this command.
But before anything else, you must connect to the SharePoint Online PowerShell. Keep in mind that you can connect to SharePoint Online using either interactive sign-in/Entra ID app registration.
App-based authentication is commonly used for automation cases (such as scheduled tasks, Azure Automation runbooks, and unattended scripts).
Next, run the following commands to create an exclusion list. This command retrieves the root and host sites of your SharePoint Online tenant and adds them to the $excludedURLs variable.
Now that we have the exclusion list, letโs retrieve the SharePoint site collections. Depending on which types of sites you wish to retrieve, run the appropriate command from the list below.
# All SharePoint Online Sites, including OneDrive
$siteCollection = Get-PnPTenantSite -IncludeOneDriveSites | Where-Object { $_.Url -notin $excludedUrls }
# SharePoint Sites only
$siteCollection = Get-PnPTenantSite | Where-Object { $_.Url -notin $excludedUrls }
# OneDrive Sites only
$siteCollection = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'" | Where-Object { $_.Url -notin $excludedUrls }
# Microsoft 365 Groups-Connected Sites only
$siteCollection = Get-PnPTenantSite -GroupIdDefined:$true | Where-Object { $_.GroupId -ne '00000000-0000-0000-0000-000000000000' -and $_.Url -notin $excludedUrls }
# Sites Without a Group
$siteCollection = Get-PnPTenantSite -GroupIdDefined:$false | Where-Object { $_.Url -notin $excludedUrls }
# Sites Connected to Teams
$siteCollection = Get-PnPTenantSite -GroupIdDefined:$true | Where-Object { $_.IsTeamsConnected -eq $true -and $_.Url -notin $excludedUrls }
# Sites Connected to Teams Channel (Private or Shared)
$siteCollection = Get-PnPTenantSite | Where-Object { $_.IsTeamsChannelConnected -and $_.Url -notin $excludedUrls }
In this example, Iโll run the command to get all sites, including OneDrive. My tenant has 29 sites, including personal OneDrive sites.
You can now display the SharePoint storage report by selecting the relevant properties. You can export to CSV, display on the screen, or in a grid. In this instance, letโs display the results in a grid.
As you can see, the output is โusableโ but not pretty. What are the issues in this current report?
The โTemplateโ is not readily recognizable. It shows the template ID instead of the template name (e.g., GROUP#0 = Team Site)
The โStorageQuotaโ and โStorageCurrentusageโ units of measurement are not clear. Is it in bytes, MB, GB?
The โOwnerโ value for Microsoft 365 Group-Connected sites is missing. You can only recognize that it has an associated group through its โGroupIdโ property.
Weโll need to do more result manipulation in PowerShell to produce a more sensible SharePoint storage usage report. But donโt worry. Weโve already provided the script for you.
Using the SharePoint Storage Usage Report Script
You can copy the code below and save it to your computer as Get-SPO
Save or Download the Script
You can copy the code below and save it to your computer as Get-SPOSiteStorageUsage.ps1. For your convenience, you can also download the script from this GitHub repository.
Note that when IncludeOwnerInfo is not specified, the Owner column will remain empty in order to improve performance. Also, keep in mind that in very large tenants, owner lookup may take several minutes because Microsoft Graph is queried separately for each site.
Run the SharePoint Storage Usage Report Script
Open a PowerShell session and change the working directory to where you saved the script.
Depending on which type of sites you want to report, choose the appropriate command below and run it in PowerShell. The result will be stored in the $spoSiteStorageUsage variable.
# Get All Sites (including OneDrive)
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'All Sites'
# Get SPO Sites Only
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'SharePoint Sites'
# Get OneDrive Sites Only
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'OneDrive Sites'
# Get Sites connected to Microsoft 365 Group
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'Microsoft 365 Group Sites'
# Get Sites connected to Microsoft Teams
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'Sites Connected to Teams'
# Get Sites connected to Microsoft Teams Channel (Private or Shared)
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'Sites Connected to Teams Channel'
# Get Sites without a Microsoft 365 Group
$spoSiteStorageUsage = .\Get-SPOSiteStorageUsage.ps1 -View 'Sites Without a Group'
For example, Iโll run the SPO sites report only.
Including Site Owner Information
By default, the script does not retrieve detailed owner info in order to improve performance and reduce Microsoft Graph API requests. You can run the script without owner lookups (we recommend it for large tenants):
Keep in mind that when you are using the IncludeOwnerInfo parameter, the connected account/app must have permission to read Microsoft Entra ID users and Microsoft 365 groups. Otherwise owner info cannot be retrieved.
Note. Retrieving owner info requires additional Microsoft Graph queries and may significantly increase execution time in tenants with hundreds/thousands of SharePoint sites.
Interpreting the Result
You can now view the report on the screen or export it to a file.
Note. The ConvertTo-Yaml cmdlet is not included in Windows PowerShell, PowerShell 7, or the PnP.PowerShell module. In order to export the report to YAML format, install the powershell-yaml module first:
Install-Module powershell-yaml -Scope CurrentUser
The script output has the following properties:
SiteName โ The SharePoint or OneDrive siteโs title.
Url – The SharePoint or OneDrive siteโs URL.
StorageQuota(GB) โ The SharePoint or OneDrive siteโs assigned quota in GB.
StorageUsage(GB) โ The SharePoint or OneDrive siteโs storage usage in GB.
StorageUsage(%) โ The SharePoint or OneDrive siteโs storage usage in percent.
Owner โ The site owner display name and email address when IncludeOwnerInfo is enabled.
Template โ The siteโs web template (i.e., OneDrive, Communication, Team Site, etc.)
SiteAttributes โ This property indicates if the site is connected to a Microsoft 365, Microsoft Teams, or Teams Channel (Private and Shared).
You can easily apply a CSS template to format your HTML report like so:
Generating a SharePoint Storage Usage Report using PowerShell provides invaluable insights into your organizationโs content usage and storage patterns. In this blog post, we delved into the step-by-step process of creating a comprehensive storage report, enabling administrators to make data-driven decisions and optimize their SharePoint environment effectively.
PowerShell proves to be an indispensable tool in managing SharePoint Online environments, and the storage report generation process demonstrated here is just one example of its capabilities. As you continue to explore PowerShellโs features, you will discover various ways to streamline administrative tasks, enhance efficiency, and empower your organizationโs collaboration platform.
By adopting this practice, you equip your organization with the necessary insights to optimize storage usage, ensure compliance, and deliver a seamless user experience, all while staying one step ahead in managing your SharePoint Online ecosystem effectively.
So, get started with the PowerShell script provided in this blog post and unlock the full potential of your SharePoint Online environment today!
You need SharePoint Administrator or Global Administrator permissions and an account that can authenticate using modern Microsoft Entra ID authentication.
You can connect using interactive sign-in with Connect-PnPOnline -Interactive or use app-based authentication with a registered Entra ID application and certificate.
Yes. The script supports filtering for SharePoint sites, OneDrive sites, Microsoft 365 Group-connected sites, Teams-connected sites, Teams channel sites, and sites without a Microsoft 365 Group.
June started in IT back in 2002. Since then, he has worked as a programmer, technical support specialist, and systems administrator. He is currently a technology consultant working with Microsoft 365, Azure, and various Messaging and Collaboration systems. June is always on the lookout for automation opportunities and prefers to write code in PowerShell whenever possible.
Excellent script! Is it possible to also report on each site’s storage utilization within the recycle bin, file versions, retention and other areas that may consume SPO storage? It would help us find those sites that are wasteful in storage consumption.
Excellent script! Is it possible to also report on each site’s storage utilization within the recycle bin, file versions, retention and other areas that may consume SPO storage? It would help us find those sites that are wasteful in storage consumption.