A migrated Excel file that reports “The workbook cannot be opened,” a blank Word document, or a suspiciously empty file-size column deserves a closer look. In the migration behind this post, we found zero-byte destination files even though the expected paths and timestamps were present.
What a zero-byte scan tells you
It identifies files whose reported SharePoint length is zero. It does not prove why they are empty, whether they were intentionally empty, or whether the source still contains a recoverable copy. A blank size displayed in a view is a clue, not the scanner’s test.

Our experience with that ShareGate job was the reason for writing the first scanner. It is a historical case, not a finding that every current ShareGate migration has this defect. Audit a migration by checking its results, regardless of which tool performed it.
Requirements
- PowerShell 7.4.6 or later and the current stable
PnP.PowerShellmodule. Check the installed module’s runtime requirements before upgrading it. - An Entra application configured for PnP interactive sign-in, with the delegated SharePoint access required to read the selected sites and file metadata.
- A signed-in account that can read the libraries being scanned. Application consent does not grant that user access to every site.
- An existing local output folder that you can write to.
Registering your own application is now part of the PnP authentication setup. Follow its permissions and consent instructions for your environment. The old advice to install MSOnline, AzureAD and SharePointPnPPowerShellOnline together is no longer part of this script’s setup.
Install-Module PnP.PowerShell -Scope CurrentUser
Get-Module PnP.PowerShell -ListAvailable | Select-Object Name, Version
Run the report
Download the revised zero-byte file scanner and save it as Scan0KBFiles.ps1. Use this dated download in place of older copies.
.\Scan0KBFiles.ps1 -SiteUrl 'https://yourtenant.sharepoint.com/sites/example' -ClientId 'YOUR-APPLICATION-CLIENT-ID' -OutputPath 'C:\Reports\ZeroByteFiles.csv'
Replace the application placeholder with its GUID. For several sites, pass a PowerShell array to -SiteUrl. If you omit -OutputPath, the script creates a timestamped report in the current folder. It refuses to overwrite an existing report.
The CSV contains SiteCollectionURL, Library, FilePath, FileName and Length. Filenames containing commas are quoted correctly. A completed scan with no matches still produces the header.
Scope and incomplete scans
The script uses one recursive, paged Get-PnPListItem traversal per accessible, non-hidden document library. It does not enumerate subsites automatically. It reports neither folders nor unknown sizes as zero-byte files.
Authentication, permission, throttling or enumeration errors stop the scan with an incomplete-report message. Keep any rows already written, but do not describe that CSV as a complete site audit. Investigate the failure and rerun to a new output file. Paging reduces request size; it is not a promise that every tenant limit or throttling condition disappears.
Recover from a verified source
For each finding, compare the destination with the source file, migration logs and available version history. Confirm the expected content and size before replacing anything. Investigate destination permissions, metadata and versions that need preserving. This script does not delete files, overwrite content, or perform a migration repair.
Validation for this revision: Syntax, file/folder filtering, unknown-size handling, CSV output and command-line defaults were checked locally with simulated metadata and connections. No live SharePoint tenant was scanned during this refresh.