How to Count SharePoint Files for an AI Data Application

Count company SharePoint files and used storage through the Microsoft 365 portal or PowerShell, without double-counting Teams documents.

Workflows

On this page

To count company SharePoint files, open the SharePoint Site usage report in the Microsoft 365 admin center, export its table and add the Files column for the sites in your inventory. With PowerShell, use Microsoft Graph's site-usage report to download and sum the same reported file counts and storage values.

This is often where a company's shared operational records live: proposals, invoices, procedures, spreadsheets and project files. The first task for an AI data application is to measure the intended sites and explain the result. The full business data inventory covers the other tools.

Choose your method and scope

MethodWhat you collectUseful when
Microsoft 365 portalPer-site file and storage reportYou want to review sites in Excel
PowerShell and GraphRaw report, included sites and summary CSVsYou want to rerun the same calculation

Decide whether you are counting all reported company sites or only specified departments. Keep a list of exclusions. A site you rarely visit may still contain years of useful business records; activity alone is not a reason to leave it out.

Before you begin

You need access to Microsoft 365 usage reporting. The Graph method needs Reports.Read.All, the appropriate reporting role and administrator consent where required. The API reports usage; it does not grant permission to read all the documents in the sites. Graph site-usage permissions and fields (opens in a new tab)

If someone else administers Microsoft 365, send:

Please export the SharePoint Site usage report with file count, used storage, site identifier, deletion status and report refresh date. We need counts for [all company sites/list of sites] for a data-volume questionnaire. Please flag anything the report does not cover.

Method 1 Use the Microsoft 365 portal

  1. Sign in to the Microsoft 365 admin center (opens in a new tab).
  2. Go to Reports → Usage, expanding Show all if needed.
  3. Select SharePoint, then Site usage.
  4. Display the site table and use Choose columns to include site identity, deletion status, Files, Active files and Storage used.
  5. Choose Export, then open the CSV in Excel.
  6. Select the sites covered by your inventory and retain one row per site.
  7. Sum Files and Storage used. Record the refresh date and the units supplied by that export.

Files is the stored-file measure, while Active files concerns files used during the selected reporting period. Storage allocated is capacity, not the space the documents currently consume. Microsoft also documents differences between sites listed in usage reports and the SharePoint admin center's Active sites view. SharePoint report definitions (opens in a new tab)

Use the report export as the evidence for your total, and describe it as a reported snapshot. Do not combine the Files total from one report with a second count of the same sites from another screen.

If site names or URLs are concealed, ask the administrator to reconcile identifiers with your agreed site list. An all-row aggregate can be useful, but it does not tell you which department owns the records.

Method 2 Count with PowerShell

In a supported PowerShell 7 session, install the reporting modules and sign in. Replace the tenant placeholder, then confirm the account shown:

Install-Module Microsoft.Graph.Authentication -Scope CurrentUser
Install-Module Microsoft.Graph.Reports -Scope CurrentUser
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Reports
Connect-MgGraph -TenantId 'your-tenant-id-or-domain' -Scopes 'Reports.Read.All'
Get-MgContext | Select-Object Account, TenantId

Download the report and inspect the site rows. The folder is created under your current local directory.

$ErrorActionPreference = 'Stop'
$inventoryDir = Join-Path (Get-Location) ('sharepoint-inventory-' + (Get-Date -Format 'yyyyMMdd-HHmmss'))
New-Item -ItemType Directory -Path $inventoryDir -ErrorAction Stop | Out-Null
$reportPath = Join-Path $inventoryDir 'sharepoint-raw.csv'
Get-MgReportSharePointSiteUsageDetail -Period D7 -OutFile $reportPath -ErrorAction Stop
$rows = @(Import-Csv -LiteralPath $reportPath)
if ($rows.Count -eq 0) { throw 'The report has no site rows. Check scope and access.' }
$required = @('Site Id', 'Is Deleted', 'File Count', 'Storage Used (Byte)', 'Report Refresh Date')
foreach ($column in $required) {
    if ($column -notin $rows[0].PSObject.Properties.Name) {
        throw "Missing report column: $column"
    }
}
$rows | Select-Object 'Site Id', 'Site URL', 'Is Deleted', 'File Count' |
    Format-Table -AutoSize

The official Get-MgReportSharePointSiteUsageDetail command (opens in a new tab) writes report data to CSV. This step reads usage reporting without downloading the business documents.

Next, select non-deleted rows and calculate. If you agreed to inventory only named sites, filter $included to those site IDs before the total is calculated.

foreach ($row in $rows) {
    if ($row.'Is Deleted' -notin @('True', 'False')) {
        throw 'Unexpected deletion status. Inspect the raw report.'
    }
}
$included = @($rows | Where-Object { $_.'Is Deleted' -eq 'False' })
if ($included.Count -eq 0) { throw 'No non-deleted sites were selected.' }
if (@($included | Where-Object { [string]::IsNullOrWhiteSpace($_.'Site Id') }).Count -gt 0) {
    throw 'A site ID is missing. Review the report before summing.'
}
$duplicates = @($included | Group-Object 'Site Id' | Where-Object { $_.Count -gt 1 })
if ($duplicates.Count -gt 0) { throw 'Repeated site IDs found. Review the report.' }
$files = [long]0
$bytes = [long]0
foreach ($row in $included) {
    $fileValue = [long]0
    $byteValue = [long]0
    if (-not [long]::TryParse($row.'File Count', [ref]$fileValue) -or $fileValue -lt 0) {
        throw 'Invalid file count. Inspect the raw report.'
    }
    if (-not [long]::TryParse($row.'Storage Used (Byte)', [ref]$byteValue) -or $byteValue -lt 0) {
        throw 'Invalid storage value. Inspect the raw report.'
    }
    $files += $fileValue
    $bytes += $byteValue
}
$included | Export-Csv (Join-Path $inventoryDir 'sharepoint-included.csv') -NoTypeInformation
[pscustomobject]@{
    Sites = $included.Count
    Files = $files
    StorageGB = [math]::Round($bytes / 1e9, 2)
    ReportRefreshDates = (($included.'Report Refresh Date' | Sort-Object -Unique) -join '; ')
    CollectedAt = (Get-Date).ToString('o')
} | Tee-Object -Variable inventorySummary | Format-List
$inventorySummary | Export-Csv (Join-Path $inventoryDir 'sharepoint-summary.csv') -NoTypeInformation
Disconnect-MgGraph

The script uses decimal GB. Keep that unit when copying the result. A number calculated by dividing bytes by PowerShell's 1GB constant is GiB and will differ even when the underlying byte total matches.

Do not treat an error as zero. If reporting is unavailable, an ID is missing or a numeric column is blank, fix the issue before presenting a company-wide count.

Keep Teams and OneDrive from overlapping this count

Teams is often the interface people use to reach a SharePoint document. Standard channel files live in the team's SharePoint site, while private and shared channels have dedicated sites. Files shared through chats use OneDrive. Microsoft's Teams content-location table (opens in a new tab)

That means “Teams files” cannot simply become another number added to your SharePoint total. Count each underlying storage location once. Keep Teams messages in a separate row with a separate unit.

Use our OneDrive inventory guide for staff work drives. A user-made copy of a document can still exist in both services; counting stored files does not deduplicate their contents.

Find historical coverage and document types

The usage CSV does not establish the oldest business record date or a breakdown of PDFs, spreadsheets and images. If the buyer requests those details, use a separate metadata inventory for the chosen document libraries.

Agree on the date definition. A file's creation time in SharePoint may describe an upload or migration rather than the year the underlying invoice or lease was written. Keep the business's known operating history separate from measured file dates.

A local sync folder can help inspect extensions, but it may cover only selected libraries or folders. Describe that scope before applying its proportions to an entire company site. Storage usage also should not be treated as the size of an eventual deliverable without checking what the export includes.

A business example

A November 2026 inventory reported 35,084 SharePoint files using 72.8 GB. Almost all the files sat in one main shared document library; the remaining sites contributed a small fraction.

That is a useful clue for a follow-up conversation: focus the next inventory on the main operational library. It does not justify ignoring smaller sites, or assuming the largest library contains only one record type.

Paste this into the AI data questionnaire

SharePoint: [file count] reported files using [storage and unit] across [site count] selected company sites. Report refreshed [date]; collected [date]. Scope: [sites or departments]. Deleted sites: [treatment]. Teams-backed sites: [included/excluded]. File types and historical coverage: [verified details or unknown].

Keep the included-site CSV with your answer. If another administrator reruns the report, they can compare the same locations instead of trying to reconstruct your scope.

Continue with the business data inventory checklist, or check your company's fit for data licensing after collecting the relevant counts.

← All guides


MIT 2026 © Nextra.