PowerShell: Set/Configure Document Library with MajorVersionLimit, MajorWithMinorVersionsLimit & require to checkout before editing

Just finished coding a PowerShell function to achieve the following:
Approval Library:
– Require content approval;
– Require items to be checked out;
– Require major versions and minor versions;
– Keep a maximum of 5 major versions and drafts for 1 major version.

Here is the PS function which I coded to satisfy the above design requirement:

function ConfiguringVersioningSettings($webUrl, $listName, $requireCheckOut, $majorVersionLimit, $minorVersionLimit){
       Write-Message "Configuring version settings for $listName..." "cyan"
       $web = Get-SPWeb $webUrl
       $library = $web.Lists[$listName]
       $library.EnableVersioning = $true
       $library.EnableMinorVersions = $true
       $library.MajorVersionLimit = $majorVersionLimit
       $library.MajorWithMinorVersionsLimit = $minorVersionLimit
       $library.ForceCheckOut = $requireCheckOut

Why do we restrict the number of versions?

Out of the box SharePoint keeps all versions in the document library. Once we enable the versioning on libraries all versions size is counted towards the site collection quota, there is no such thing as storing deltas in this case, they’re the full versions. I.e. each time we save the document, SharePoint stores as a separate copy of complete document in the database though we make a small change. Just imagine If we have a 100 MB document with 20 different versions (Around 2 GB of storage capacity). With large documents, even a small but active library can eat up your database in a hurry. If you have a limited site collection storage capacity, this is going to be a big issue to store more number of documents as database reaches it max storage capacity very soon. So, restrict at max 3 major and 3 minor versions at any point in time in the document library.

If you forget to set the limitation, there is no way from SharePoint out-of-the-box to house keep/manage specific versions from document version history. Either you have to remove/delete all versions or all minor versions

To enable version history on a document library choose the library you would like to set version settings.

Library Settings > in the settings page, under General Settings > click Versioning Settings:

– Check the checkbox “Create major and minor (draft) versions” option

– And, check the checkboxes to keep 3 major and 3 minor versions

Happy Point Sharing!