Can we define a default value for the number of major versions inside our SharePoint libraries, that get applied to new and existing libraries

john john 1,011 Reputation points
2023-05-28T14:58:47.19+00:00

When we create a new SharePoint site and/or new document libraries, they will have their number of default major versions to 500

User's image

so is there a way to change this number to be 50 instead of 500 and apply this settings to new and existing libraries ?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,229 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,604 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yanli Jiang - MSFT 31,571 Reputation points Microsoft External Staff
    2023-05-29T06:14:17.6833333+00:00

    Hi john ,

    Welcome to Q&A forum!

    Yes, you can set the default major version for the entire site through PowerShell. SharePoint in Microsoft 365 Library Settings allows a range of 100-50000 major versions, you can choose within this range. Then run the following PowerShell in the SharePoint Online Management Shell as an admin:

    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    #Import SharePoint Online PowerShell Module
    Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
      
    Function Set-SPOSiteVersionHistoryLimit()
    {
        param
        (
            [Parameter(Mandatory=$true)] [string] $SiteURL,
            [parameter(Mandatory=$false)][int]$VersioningLimit = 100
        )
        Try {
            #Get Credentials to connect
            $Cred= Get-Credential
       
            #Setup the context
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
            $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)       
             
            #Get All Lists from the Web
            $Lists = $Ctx.Web.Lists
            $Ctx.Load($Lists)
            $Ctx.ExecuteQuery()
              
            #Array to exclude system libraries
            $SystemLibraries = @("Form Templates", "Pages", "Preservation Hold Library","Site Assets", "Site Pages", "Images",
                                "Site Collection Documents", "Site Collection Images","Style Library")
              
            #Get All document libraries
            $DocumentLibraries = $Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False -and $_.Title -notin $SystemLibraries}
             
            #Set Versioning Limits
            ForEach($Library in $DocumentLibraries)
            {
                #Get the Library's versioning settings
                $Library.Retrieve("EnableVersioning")
                $Ctx.ExecuteQuery()
     
                #powershell to set limit on version history
                If($Library.EnableVersioning)
                {
                    #Set versioning limit
                    $Library.MajorVersionLimit = $VersioningLimit
                    $Library.Update()
                    $Ctx.ExecuteQuery()
                    Write-host -f Green "Version History Settings has been Updated on '$($Library.Title)'"
                }
                Else
                {
                    Write-host -f Yellow "Version History is turned-off at '$($Library.Title)'"
                }
            }
        }
        Catch {
            Write-host -f Red "Error:" $_.Exception.Message
        }
    }
      
    #Call the function to set version history limit
    Set-SPOSiteVersionHistoryLimit -SiteURL "https://domain.sharepoint.com/sites/sitename"
    
    
    
    

    In the test, the value I filled in is 100, and the result is as follows:

    05291

    05292

    Note: please select the appropriate number of versions according to your needs, so as not to take up a lot of memory in the version history and affect the performance of the site.


    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.


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.