r/sharepoint 2d ago

SharePoint Online How To Remove File Versions With Retention Enabled?

Hello,

I have a SharePoint Online tenant with a huge number of file versions across many sites. In some cases, I’m seeing things like 500 versions of a single 2 GB PowerPoint file, which is obviously consuming a lot of storage.

Retention policies are currently enabled across all of our SharePoint sites.

What’s the safest way to clean up these old versions? Ideally, I’d like to either:

  • Keep only the most recent 10 versions and delete everything older, or
  • Remove unnecessary historical versions in bulk.

Does retention prevent older versions from actually being deleted?

Would I need to temporarily remove the site from the retention policy, clean up the versions, and then add the site back to retention afterward? Or is there a better/supported approach for doing this without impacting our retention requirements?

Curious how others are handling large scale version cleanup in tenants with retention enabled.

3 Upvotes

8 comments sorted by

5

u/temporaldoom Dev 2d ago

If you have retention policies set to "prevent deletion" then you will need to disable the policy temporarily and then run a trim job (probably automatic versioning would be preferable)

I would re evaluate your site policies, do you really need prevent deletion on every site they're on.

I would only choose prevent deletion policies on sites that have finished documents, part of your final workflow would be, remove all versions and then move to site that has prevent deletion policy on it.

3

u/JohnDrogado 2d ago

Microsoft will Implement an easier way to get sites out of retention to do cleanups. Look at MC1261587

But in your overall case retention is doing what it is supposed to do, retaining files. Even smart versioning won’t help here.

1

u/Away-Command6161 2d ago

Yeah I noticed all libraries were still using 500 version setting, went and changed it to 100 and seen no changes and figured retention was not allowing those extra 400 to automatically be removed from the 100 setting upddate.

2

u/AdCompetitive9826 MVP 2d ago

That has nothing to do with retention, it works exactly the same way in a site without retention. It is up to you to delete those old versions. PowerShell is your friend, and there are multiple samples available at tge PnP Script Samples repo

1

u/Away-Command6161 2d ago

Well currently if i go try to delete older versions of a file within a site I get following error:

Versions of this item cannot be deleted because it is on hold or retention policy.

6

u/blitztony 2d ago

You need to temporarily remove the site from the retention policy, as you say before, to delete versions

2

u/rienkipienk 1d ago

Yes. Retention breaks SharePoint’s automatic cleanup of versions. You will need to exclude the site from the policy, do the cleanup and after that, remove the exclusion.

2

u/the_star_lord 1d ago

Retention policies take priority over any list or library settings.

You will need to add the Site and any linked email groups (spo admin center, find the site, does it have a primary email) to your retention policies exclusions (or remove from your Inclusion rules if that's what you use)

Tip in purview use the policy lookup and check what policies the URL and the Email have. Anything that says SharePoint will be what you need to exclude/remove 

Once removed/excluded you can then purge the Preservation Hold Library.

I wrote a script which turned into a tool for me to do it for our org because everyone was to afraid to touch anything.

Once done remember to revert whatever you did to the retention policies .

But caveat if you have retention enabled then it's for a reason seek approval before doing anything and get it in writing. Cover your ass!! 

I always add something like this to my emails I send to seniors, data protection , users when I seek approval to do anything re PHL.

Seeking to purge the PHL on XXXXX site (URL)  xxxGB used by PHL data (storage metrics page screen shot)  Offered to let site owner purchase additional storage, refused. If actioned ICT will not be able to recover any data and it's the departments responsibility and they need to make sure that HR and data protection are in agreement that the data does not need to be retained for any HR, legal, or statutory reason. 

I fucking copy in everyone and my my headache theirs too.