Optimizing storage in SharePoint Online part 1 - implement an automatic version policy

Organisations have stored vast amounts of data in SharePoint Online, and this is still growing. Lots of them are hitting their subscription storage limit and are in need or reducing storage. Plenty of them also purchase additional storage on top of their subscription, which comes with a substantial cost. This article series is all about optimizing storage and part 1 is about enabling automatic version policies throughout the tenant and for existing sites is a way to help reduce clutter and get back some storage space.

Setting the scene 

Version history and control in SharePoint Online provide a valuable set of capabilities to support all kinds of collaboration and content management scenarios. This is also tightly integrated into the Office applications and is fundamental to co-authoring. Although this capability is much appreciated, it can sometimes be a cause of storage issues for the tenant. Large files like PowerPoints with embedded videos or Excel workbooks of several GB with a large set of historic versions can clutter the available storage over time. There is also no need to maintain large amounts of versions for longer times, except for some very specific scenarios.

Luckily, Microsoft already provided many options to limit the amount of versions for document libraries. The version settings for the document library would allow you to limit the number of version to retain. But even then, the version clutter for large files would still take up too much space.

Automatic version control

In June 2023, Microsoft added SharePoint: Improvements for document library version history limits (Roadmap ID: 145802) to the Microsoft 365 roadmap, which would help to handle version history control in a smarter way. The idea behind this was to distinguish between low and high value versions. Microsoft explains this in Plan version storage for document libraries - SharePoint in Microsoft 365 | Microsoft Learn, but the essence is that as versions are created, users have access to the following versions (Microsoft contents):

  • All versions created within 500 count limit in the first 30 days.
  • Hourly versions (versions created at the top of the hour) between a 30 to 60-day period.
  • Daily versions (versions created at the beginning of each day) between a 60 to 180-day period.
  • Weekly versions (versions created at the beginning of the week) beyond 180 days or more are available indefinitely until the maximum 500 count limit has reached.

The service trims the intermediate versions as the above milestones are reached, and therefore storage is managed in a smarter way.

An organisation could benefit (reduce storage costs) by planning for version control both tenantwide and for scenarios that need specific settings.

Tenantwide configuration

To enable automatic versioning at a tenant level, you can configure this in the SharePoint Online Admin Center.under "Settings > Version history limits".

Set version history limits manually

By default, (for now), the manual option is enabled. This setting also allows you to specify how long to retain versions. The default setting is to never delete historic versions.

Set version history limits automatically

Setting the automatic version will enable the new smarter way to newly created document libraries. It does not enable it for document libraries that were created before enabling the automatic setting.

So, for existing libraries, you will need to set this separately per site or library.

Setting automatic version control in bulk

In case you want to configure the automatic setting for all modern sites, you could do this with your trusted friend, PnP.PowerShell.

After connecting to the SharePoint Online Admin Center, you can query all sites based on the template ID for which you want to enable the automatic version control:

$sites = Get-PnPTenantSite `
    -Connection $tenantConnection | `
    Where-Object { $_.Template -match 'GROUP#0|TEAMCHANNEL#0|TEAMCHANNEL#1' }

 You may wish to include other modern sites like STS#3 or SITEPAGEPUBLISHING#0.

After that you can loop through the list of sites, connect to the site via the URL-property of the site object and finally set the automatic version setting using the Set-PnPSiteVersionPolicy cmdlet: This cmdlet can also set the other version control policies with options to specify specific version limits and selected expiry.

# Set the version policy for the site
Set-PnPSiteVersionPolicy `
    -EnableAutoExpirationVersionTrim $true `
    -Connection $siteConnection

After this, all sites from the $sites-list will be enabled for the new version control. This also includes new document libraries being created after the fact. And it also creates a request to set the file version trim mode as AutoExpiration for existing document libraries that enabled versioning.

# Connect to the SharePoint Online admin site
$tenantConnection = Connect-PnPOnline `
    -Interactive `
    -ClientId '{clientid}' `
    -Url 'https://contoso-admin.sharepoint.com' `
    -ReturnConnection

# Get all sites in the tenant that match specific templates
$sites = Get-PnPTenantSite `
    -Connection $tenantConnection | `
    Where-Object { $_.Template -match 'GROUP#0|TEAMCHANNEL#0|TEAMCHANNEL#1|SITEPAGEPUBLISHING#0' }

foreach ($site in $sites) {

    Write-Output "Connecting to site: $($site.Url)"

    # Connect to the site using the tenant connection
    $siteConnection = Connect-PnPOnline `
        -Url $site.Url `
        -ClientId '4c3396ec-233a-4f0c-8cb8-bfc23fb03b30' `
        -ReturnConnection `
        -Connection $tenantConnection

    # Set the version policy for the site
    Set-PnPSiteVersionPolicy `
        -EnableAutoExpirationVersionTrim $true `
        -ApplyToNewDocumentLibraries `
        -Connection $siteConnection
}

Conclusions

The automatic version trimming is one of the capabilities that will help to optimize storage using a tenant wide approach or deviate when specific sites need alternative versioning controls. Make sure to test this first, prior to unleashing it to a production-tenant.

Surely, it's not the only solution to the problem. In the next parts of this series, I will discuss other capabilities in Microsoft 365 and Microsoft Purview. Stay tuned!