top of page
  • Writer's pictureKasper Larsen

Deleting File Versions to reduce the SharePoint Storage Consumption

Updated: Nov 20, 2023


This is a fellow-up post on the MS365thinking: Don't pay more for SharePoint Storage than you have to :-) post, where I went through the options you have when reducing the SharePoint Storage consumption.


The first action could be to reduce the default number of versions from 500 to a more reasonable number, like 50. (Edit: later found out that min is 100)




This will minimize any future storage increase but will not delete any existing versions. So, we will have to trim the existing libraries.



In this post I will show how you can reduce the consumption using the PnP.PowerShell command Remove-PnPFileVersion


First of all, let's provide some evidens on how SharePoint storage is calculated in a way that will convince your management that you should investigate this.

This script will create a brand-new Modern SharePoint site collection (STS#3) or use the site collection specified by you.

The script will then create a number of major and minor versions using a file provided by you:


#how many major versions the script should create $majorVersionCount = 30 #how many minor versions that should create per major version $minorVersionCount = 10

It will then calculate the current amount of SP storage used in this site collection.


If the file you provided is 5MB then we would expect the storage to be 5*10*30 = 1500 MB.

Wait...I have heard that Microsoft only saves the diffs when dealing with modern office files as these are XML files behind the covers. So the 300 versions of the file will only take up a smidge more than 5 MB, right?

Yes, you are correct, but that is not the way SharePoint storage is calculated :-) as Microsoft calculates this as the aggregation of File Size for each version of the file.


The re-calculation of Storage seems to be on a schedule so you should expect that the new storage numbers will take serveral hours before it shows up in the Admin center










Once we can see the Storage being consumed on our site collection, it is time to bring out the harvester:



Please be aware that the script is a sample and NOT production grade code. That will most likely be a number of questions you will need to address before you can start trimming the file versions.

Typical questions could be:


  • Which Site Collections should not be trimmed.

  • Which archived Site Collections should be unarchived and trimmed and then archived again.

  • Are we going to use the same pruning parameters on all sites, or should we only trim the minor versions on some Site Collections.

  • Are some of the files tagged as records and should receive special treatment

  • and so on :-)


Have fun and remember Sharing is caring



163 views0 comments

Recent Posts

See All

Comments


bottom of page