featured-sharepoint-storage-tree2
|

See what is using your SharePoint storage, down to the file

One of the sites I was testing had an app package that took up 36MB of space although the file itself was 2MB. The file wasn’t corrupted. I uploaded the same file 20 times during web part testing and SharePoint kept all the copies; moreover, the site counted the whole amount of copies into quota without providing any notification on the reason.

This file is easily accessible via the built-in Storage Metrics page (/_layouts/15/storman.aspx), if you know where to find it. It provides you with the totals of folders of one site at a time. However, this page does not provide you with the split between old versions and currently used files, and that split is what you need if the site reaches its quota.

The most straightforward method is to subtract the currently used size from the total file size. However, this method provided me with incorrect results. The same test site had an image library with 38MB of pictures that used 98MB of storage. None of these pictures had any old versions. The remaining 60MB of space is the result of previews and renditions that SharePoint automatically creates for images. And there is no way to recover it with a limit on versions. Any script, that provides you with “total – current” as a version history, will tell you to reduce versions, which aren’t even there.

So I built a scanner that does the split properly, and a treemap to look at the result.

Install-PSResource SPStorageTree
Get-SPStorageTree -Site https://contoso.sharepoint.com/sites/ProjectHub -ClientId <your-app-id> -Open

If you would rather click than type, there is a Windows app as well, shown further down.

Since it reads all document libraries available on the site, even the system ones such as Site Pages and the galleries, the total number displayed matches the one indicated in the admin center. It then opens the report in a single HTML file in your browser. The process does not require any uploading to a server and the viewer runs off-line.

Treemap of a SharePoint site where each tile represents a library, folder or file, sized by its storage, with a contents table next to it
The built-in sample site (made-up data). Each tile is a library, folder or file, sized by the storage it uses.

Each of the tiles represents a library, folder or file sized by its storage. As you go inside a folder, the contents table alongside follows you. You can size your tiles based on the current version only, version history only or on what you will get back, which is when it becomes handy.

How much would trimming versions really save

This is the Version bloat tab that responds to the real question that gets asked: if we put a limit on versions, how much do we get back? Choose either Keep latest or Delete older than, and then select a number, and it will display the amount of space that gets cleared and which libraries and files gain the most.

Version history what-if showing the space reclaimed by keeping the latest 25 versions, with a curve for other limits and the libraries and files that gain the most
Keep the latest 25 versions: 21.2 GB back on the sample site, and the curve shows every other limit.

In the case of files with a significant revision history, the scanner retrieves the true size of each previous version. Thus, the numbers provided for them are precise. In all other cases, estimates are performed, and the screen informs about the percentage of estimation in the figure. An unedited file (version 1.0) will always have zero to reclaim no matter how large the total appears. This is the image library problem mentioned above, resolved.

One note regarding these figures prior to taking action on them. In case there is a retention policy or hold in effect for the site, the trimmed versions will end up in the Preservation Hold Library and no space is freed. Check that first.

One site, a site with subsites, or the whole tenant

Get-SPStorageTree -Site https://contoso.sharepoint.com/sites/ProjectHub -ClientId <your-app-id> -IncludeSubsites -Open
Get-SPStorageTree -Tenant contoso -ClientId <your-app-id> -Top 5 -Open

The tenant mode will retrieve all the sites along with their storage totals in one single request and then it will scan the top five in detail. The rest will be displayed as striped tiles showing only the total storage size.

Tenant view in dark mode with three sites scanned in detail and the rest shown as striped summary tiles with their storage totals
Tenant mode on the sample tenant: three sites scanned in detail, the rest summary only.

Prefer clicking? There is a Windows app

If you would rather not type commands, run Start-SPStorageTree or double-click SPStorageTree.exe in the module folder. Sign in, select the sites from the list, click Scan, and the viewer opens with all of them together. SharePoint admins get every site in the tenant with its size to pick from. Everyone else pastes the URLs of the sites they own.

The SharePoint Storage Tree window after signing in, listing the tenant's sites with their sizes, three of them selected, and the Scan button
The sample tenant (made-up data) after signing in. The checkbox in the column header selects every site the filter shows.

While it runs you can see which site and library it is reading. A site it can’t open is listed with the reason, and the rest still finish.

The SharePoint Storage Tree window during a scan, with a progress bar, the site and library being read, and the message log
A scan in progress on the sample tenant.

The exe is a small launcher, so it still needs PowerShell 7.4 and PnP.PowerShell, and it tells you the command to run if either one is missing. It is not code-signed yet, so the first time Windows may show Windows protected your PC. Choose More info and then Run anyway.

The parts that tripped me up

Most of the time spent was dedicated to investigating what SharePoint returns, so here’s what it returns, tested in a lab tenant.

  • The property SMTotalSize, that should contain the file’s actual total, is returned by PnP in the form of a lookup value. The bytes are stored in .LookupId, but not in the value itself.
  • Files from the galleries (master pages, themes, web parts) have the value of SMTotalFileStreamSize as 0 and File_x0020_Size with the actual size. Look only at the former and those files appear empty.
  • It’s enough to have a read-only application registration with AllSites.Read permission to scan a site, and you get file-by-file exactly the same result as having Full Control permissions. Tenant sites list works differently: Get-PnPTenantSite refuses AllSites.Read and AllSites.Manage and worked only with AllSites.FullControl.
  • Being a SharePoint or Global Administrator does not allow you to read the files from a site. In order to scan the site fully you will need to have site collection admin permissions of the particular site. The tool will continue even if it fails to read a site, marking it in the report.
  • Device code sign-in is blocked in tenants with Security Defaults (AADSTS530035 error), so the tool logs in via a browser.

The Copilot angle

Since the scan is aware of when the files were last modified and their names, it will also point out documents which haven’t been modified in years, duplicate files and temp files. Copilot will reply based on whatever the user has access to, and it is unaware that a budget from 2021 has become irrelevant. The list of outdated and duplicate documents which Copilot will be able to read and understand, complete with the explanation for the flagging, is included in the Copilot readiness tab, so you can archive or restrict them before you roll out Copilot. If you also want to check who can reach those files, I covered that in Find SharePoint oversharing before you switch on Copilot.

Copilot readiness table listing stale and duplicate documents with the reason each one is flagged
Stale and duplicate documents Copilot can read, with the reason each one is flagged.

Every table exports to CSV. If you want to share a report outside the admin team, add -ExcludeUserNames and it leaves people’s names out.

It is read only and open source, on the PowerShell Gallery and GitHub. You need PowerShell 7.4 and your own app registration for PnP PowerShell, and the README has the one command that creates it.

Similar Posts

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.