--- title: "Report SharePoint Sites with File Counts and Storage Usage" slug: "dex-wf-sharepoint-sites-storage-report" updated: 2026-11-30T16:12:50Z published: 2026-11-30T16:12:50Z canonical: "documentation.sysaid.com/dex-wf-sharepoint-sites-storage-report" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.sysaid.com/llms.txt > Use this file to discover all available pages before exploring further. # Report SharePoint Sites with File Counts and Storage Usage Inventory every SharePoint site in your tenant with item counts and storage consumption in MB. **Complexity:** Intermediate. **Impact:** read-only + reporting + capacity-planning + sharepoint + audit. ## Why use this workflow SharePoint storage in Microsoft 365 is a finite resource. Tenants receive a base allocation plus any add-on storage SKUs. Over time, abandoned team sites, video-heavy document libraries, and legacy migration landing zones can consume that pool, leading to overage charges, failed uploads, and `Storage quota exceeded` errors. This workflow produces a tenant-wide inventory of every SharePoint site with two metrics per site: **item count** (files and folders at the root level of the default document library) and **storage used in MB**. Run it as part of a capacity review, before purchasing additional SharePoint storage, or when investigating which sites drive growth. The report is also useful during mergers, divestitures, and data-lifecycle audits where you need to justify retention or archival decisions. ## Expected outcomes - A sorted list of every SharePoint site in the tenant (communication sites, team sites, the root site, hub sites, and the Content Type Hub). - Storage consumed per site in megabytes, from the drive `quota.used` property or the root folder `size`. - File and folder count at the default document library root for each site. - A grand total of storage used across the tenant. - Exportable CSV output for capacity planning, chargeback, or executive reporting. ## Risks and considerations - **Permissions:** `Sites.Read.All` is required to enumerate all sites. The `/sites/getAllSites` endpoint is inconsistent and often returns 403. Use `/sites?search=*` instead. - **Root-level counts only:** `folder.childCount` at the root is not a recursive file count. Sites with nested folders under-report unless you recurse or use the SharePoint usage report. - **Quota data is eventually consistent:** The `quota.used` value on a drive can lag. For exact chargeback numbers, cross-reference with the Active sites report in the SharePoint admin center. - **Throttling:** Large tenants can hit Graph throttling (HTTP 429). Add retry-with-backoff logic and respect the `Retry-After` header. - **Personal OneDrive sites** are excluded by the search endpoint by default. To include them, query `/users/{id}/drive` separately. - **Read-only:** This is an audit. Do not combine it with bulk-delete operations without owner sign-off and a recycle bin retention check. ## Required permissions | Permission | Why it's needed | | --- | --- | | Sites.Read.All | Required to enumerate every SharePoint site in the tenant and read its metadata. | | Files.Read.All | Required to read drive and driveItem properties (size, childCount, quota) across all sites. | | Reports.Read.All | Optional: needed if you pull storage data from the SharePoint usage reports instead of per-drive quota. | ## Ask Dex Paste the prompt into a Dex conversation. ### Prompt for IT admins ``` List all SharePoint sites in the tenant with the number of files at each site's document library root and the total storage used in MB. Sort by size descending and include the grand total. ``` ## Manual steps (admin center) The interface path gives you most of the data without scripting, though item counts are aggregated per library rather than per site. 1. Sign in to the [Microsoft 365 admin center](https://admin.microsoft.com) as a Global Administrator or SharePoint Administrator. 2. In the left navigation, expand **Admin centers** > **SharePoint** to open the SharePoint admin center. 3. Go to **Sites** > **Active sites**. 4. Click the **Storage used (GB)** column header to sort descending. The largest sites appear first. 5. To add the file-count metric, click **Customize columns** in the toolbar and turn on the **Files** column (if available in your tenant). Some tenants expose this through the **Files viewed or edited** usage column instead. 6. Click **Export** in the toolbar to download a CSV of all sites with URL, storage used, storage limit, last activity date, and owner. 7. For more granular metrics, go to **Reports** > **Usage** > **SharePoint activity** and **Reports** > **Usage** > **SharePoint site usage**. The site usage report includes file counts, active file counts, and storage used per site. 8. Export both reports and join them on `Site URL` in Excel or Power BI to build the combined view. **Tip!** The Active sites list caches data, so it can be out of date. Usage reports refresh on their own schedule. ## Microsoft Graph API Three Graph calls per site: list all sites, list drives per site, and inspect the drive root. Aggregate the results client-side. ### Step 1: Enumerate all sites The reliable way to list every site is a wildcard search. The `getAllSites` endpoint frequently returns 403 even with full permissions. ``` GET https://graph.microsoft.com/v1.0/sites?search=*&$select=id,displayName,name,webUrl ``` Response: ``` {  "value": [    {      "id": "contoso.sharepoint.com,,",      "displayName": "Marketing Internal",      "webUrl": "https://contoso.sharepoint.com/sites/MarketingInternal"    }  ] } ``` ### Step 2: Get the default drive for each site ``` GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives?$select=id,name,quota ``` The `quota.used` property returns storage consumption in bytes. Not all drives populate quota data. Fall back to the root folder `size` if `quota` is empty. ### Step 3: Get root item count and fallback size ``` GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root?$expand=children($select=id,name,file,folder) ``` Key fields in the response: - `size`: total bytes stored in the library (root and all descendants). - `folder.childCount`: number of items at the root level only. - `children[]`: each root item with a `file` or `folder` facet. ### Step 4: Convert and aggregate Convert bytes to MB: `MB = bytes / 1048576`. Sort by size descending and sum for a tenant total. ### Handling throttling If you receive HTTP 429, read the `Retry-After` header (in seconds) and pause before retrying. Batch drive-root calls with `$batch` (maximum 20 requests per batch) to reduce round trips in large tenants. ## PowerShell The approach uses the **Microsoft.Graph** PowerShell SDK to produce the same report programmatically, handling pagination and quota fallback, and exporting to CSV. ### Prerequisites 1. Install the Graph SDK: `Install-Module Microsoft.Graph -Scope CurrentUser` 2. You need the **SharePoint Administrator** or **Global Reader** role. 3. Consent to `Sites.Read.All` and `Files.Read.All` on first run. ### Approach 1. `Connect-MgGraph` with the required scopes. 2. `Get-MgSite -Search '*'` enumerates every site (use `-All` to paginate). 3. For each site, `Get-MgSiteDrive` returns its document libraries. 4. For the default drive, inspect `Quota.Used` first, then fall back to the root `Size` property. 5. `Get-MgDriveRoot -ExpandProperty Children` returns the child count. 6. Sort the results by size and write them to a CSV file.