How to set versioning limit on SharePoint online library using power shell

ambika devnale 21 Reputation points
2024-02-12T07:12:39.8+00:00

Hello everyone, I'm experiencing a storage issue on my SharePoint online tenant, and I'm trying to reduce the space occupied by old versions of documents. Currently, the major version limit is set to 500 by default, causing some documents to have 100/200+ versions, each taking up 2-3 GB of space. I'm attempting to set the major version limit to 10 via a Powershell script which is in the testing phase.

My questions are:

  1. Can I set the major version limit to 10 via a Powershell script?
  2. If I set the limit to 10, will versions older than 10 be automatically deleted/purged, or do I need to delete them manually?
  3. I came across an article that mentioned a feature that would allow setting version limits on a tenant level. When will this feature be globally available?

Here's the link to the article for reference: https://www.microsoft.com/en-us/microsoft-365/roadmap?filters-SharePoint&searchterms=145802

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2024-02-13T06:14:02.4033333+00:00

    1.You could use following PnP PowerShell to set the major version limit to 10.

    $SiteURL = "https://tenant.sharepoint.com/sites/emilytestnew"
    $LibraryName = "Documents"
     
    #Connect to SharePoint Online site
    Connect-PnPOnline $SiteURL -Interactive
     
    #Get the Library
    $Library = Get-PnPList -Identity $LibraryName
     
    #Set Version History Limit
    Set-PnPList -Identity $Library -MajorVersions 10
    

    2.Per my test, after setting the major version limit to 10, once you add a new version, SharePoint will automatically delete redundant versions, leaving only 10 versions.

    3.The new feature you mentioned above rollouts start at March 2024.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.