SharePoint Online: PowerShell to Disable Versioning

Requirement: Disable Versioning in SharePoint Online using PowerShell.

How to Disable Versioning in SharePoint Online?

The versioning feature in SharePoint Online creates a copy of items when someone changes a document so that we can track every change to the document and revert to the old version if needed. Although it’s a nifty feature, you may need to turn it OFF every so often. While it is possible to turn OFF versioning in SharePoint Online lists by setting the “Create a version each time you edit an item in this list?” option to “No”, The “No versioning” option is removed in the document library’s versioning settings! By default, versioning is enabled in SharePoint Online document libraries.

sharepoint online powershell disable versioning

There is no way to disable the version history of a document library from the web user interface. So, we are left with PowerShell! Let’s see how to turn off versioning in SharePoint Online.

SharePoint Online: PowerShell to Disable Versioning

Let’s disable versioning in a SharePoint Online document library using PowerShell.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
Function Disable-SPOVersioning()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName
    )
    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 the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
         
        #sharepoint online powershell disable versioning
        $List.EnableVersioning = $False
        $List.Update()
        $Ctx.ExecuteQuery() 
        Write-host -f Green "Versioning has been turned OFF at $ListName"
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
 
#Set Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$ListName="Migration Documents"
 
#Call the function 
Disable-SPOVersioning -SiteURL $SiteURL -ListName $ListName

This PowerShell disables version history on the given document library! How about disabling version history in all document libraries of a SharePoint Online site collection?

PnP PowerShell to Disable Versioning on a List

How about disabling version history in a SharePoint Online document library using PnP PowerShell? To disable versioning in SharePoint Online using PnP PowerShell, follow these steps:

  1. Connect to your SharePoint Online site using the Connect-PnPOnline cmdlet.
  2. Let’s assume that you want to disable versioning for a specific list on a site. Therefore, you’ll need to pass the Site URL and list name in question.
  3. Set the EnableVersioning property to “False” to disable versioning. This property is a Boolean value that indicates whether or not to enable versions. In this case, we’ll set this value to $false since we want to completely disable versioning.
  4. That’s all there is to it! After running this PowerShell script, versioning will be disabled for the specified list in your SharePoint Online site collection.
#Set Parameter
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$ListName = "Migration Documents"

#Connect to the site
Connect-PnPOnline $SiteURL -Interactive

#Set versioning settings of the List
Set-PnPList -Identity $ListName -EnableVersioning $False

Disable Versioning in All Document Libraries of a SharePoint Online Site

Let’s turn off version history in the SharePoint Online site collection:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Function to Disable Versioning on All Document Libraries in a SharePoint Online Site
Function Disable-SPOVersionHistory()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL
    )
    Try {
        Write-host -f Yellow "Processing site:"$SiteURL

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Global:Credentials
  
        #Get the site, subsites and lists from given site
        $Web = $Ctx.web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Lists)
        $Ctx.Load($web.Webs)
        $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
        $DocLibraries = $Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False -and $_.Title -notin $SystemLibraries}
        ForEach($Library in $DocLibraries)
        {
            #disable versioning in each document library
            $Library.EnableVersioning = $False
            $Library.Update()
            $Ctx.ExecuteQuery() 
            Write-host -f Green "`tVersioning has been turned OFF at '$($Library.Title)'"
        }
 
        #Iterate through each subsite
        ForEach ($Subweb in $Web.Webs)
        {
            #Call the function recursively
            Disable-SPOVersionHistory($Subweb.url)
        }
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Set Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"

#Get Credentials to connect
$Cred= Get-Credential
$Global:Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Call the function to disable versions on all document libraries
Disable-SPOVersionHistory -SiteURL $SiteURL

This disables versioning in all document libraries (Except Hidden and excluded system libraries) of the given site collection. Here is another post on configuring version history settings SharePoint Online: SharePoint Online: Enable Versioning using PowerShell

Enable “No versioning” and remove the Minimum Versioning Limit at Tenant Level

You can enable “No versioning” and disable the minimum version requirement of 100 at the tenant level using this PowerShell cmdlet:

Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

#Parameters
$AdminCenterURL="https://Crescent-admin.sharepoint.com"

#Setup Credentials to connect
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)

Set-SPOTenant -EnableMinimumVersionRequirement $False

It takes a while to reflect this change (It took me 5 min for me), and enables the “No versioning” option under versioning settings and removes the minimum version of 100 requirements (So that you won’t get “You must enter a number between 100 and 50000.” validation message!)

disable versioning in sharepoint online

Create a new document library with Version history turned OFF

Here is another trick to creating a document library with versioning disabled:

  1. Go to: Site Contents page >> Click on “Add an App” >> Pick “Document Library”. 
  2. Click on the “Advanced Options” link. Now, you’ll get an option to disable versioning on the new document library you are going to create. 
  3. Just choose “No” for “Create a version each time you edit a file in this document library”?.
    create document library with version history disabled

This creates a new document library without the versioning feature enabled.

Conclusion

The versioning feature allows multiple versions of a document or file to be saved and tracked over time. However, there may come a time when versioning is no longer needed or desired. There are several reasons one may want to disable versioning in SharePoint, such as to conserve storage space and reduce costs. As explained in this article, disabling versioning in SharePoint Online is a simple process that can be performed through PowerShell.

How to turn ON versioning in SharePoint?

To turn on versioning in SharePoint Online, go to the document library or list where you want to enable versioning. Click on the gear icon and select “Library settings” or “List settings.” Under “General Settings,” click on “Versioning settings.” From there, you can choose to enable versioning and set the number of versions to keep. BTW, the Version history is enabled by default in SharePoint Online.
More info: Enable version history in SharePoint Online

How to upload a new version in SharePoint?

To upload a new version in SharePoint, you can open the document you want to update and make changes to it. Then, save the document and SharePoint will automatically create a new version of the document with metadata such as who saved it and when it was created. Alternatively, if you upload a document with the same name, and in the same location, a new version will be created!

How do I delete old versions of files in SharePoint?

To delete old versions of files in SharePoint Online, go to the document library where the file is located, Right-click on the file, and select “Version History.” From there, you can select the version you want to delete and click “Delete.” You can also choose to delete all previous versions of the file at once by clicking on “Delete all versions” from the version history page.
More info: How to delete version history in SharePoint?

How to restore version history in SharePoint?

To restore version history in SharePoint, you can go to the version history page of the file or item and select the version you want to restore. Then, hover next to the version and select the down arrow to get a list of options. From there, select “Restore” to restore the selected version. SharePoint moves deleted versions to the recycle bin, where they can be restored within 93 days.
More info: How to restore version history in SharePoint?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

15 thoughts on “SharePoint Online: PowerShell to Disable Versioning

  • Is there also a way to set it to max X versions? Let’s say 3 or 5, just in case.
    And if so, can this script also delete the contents of the previous made versions and leave X amounts (from the line above)?

    Reply
  • Hi,

    I already turned off no versioning but still getting version history, anyone facing same issue?
    Im using business plan 2

    Reply
  • You saved me. This is just what I needed. Thank you very much!

    Reply
  • There is an option to turn it off now in the web user interface

    Reply
    • Im digging through options looking for where to turn it off. Can you share the exact location? Thanks

      Reply
      • It depends on your Tenant Level settings: “EnableMinimumVersionRequirement”. Use the PowerShell script in this article to set it to $False to get the “No Versioning” option in List or Library >> Versioning Settings.

        Reply
  • Have you considered developing these scripts to be compatible with MFA?

    Reply
    • Connect-SPOService without “Credential” parameter or Connect-PnPOnline with “Interactive” switch can handle MFA enabled accounts!

      Reply
      • How do you change the scripts to use those approaches to work with MFA? I need to disable versioning but have no background in Powershell scripting what so ever.

        Reply
        • Using Connect-SPOService without the “Credential” parameter or Connect-PnPOnline with the “Interactive” switch can accommodate accounts with MFA!

          Reply
  • It still checkout. However, the dll could be in a different folder (I use search everything to look at the libraries).

    First, install the module (if we are not installed it)

    Install-Module -Name Microsoft.Online.SharePoint.PowerShell
    And change the libraries as follow.

    Add-Type -Path “C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.20518.12000\Microsoft.SharePoint.Client.dll”
    Add-Type -Path “C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.20518.12000\Microsoft.SharePoint.Client.Runtime.dll”

    Reply
    • Well, If you have the Microsoft SharePoint Online PowerShell Module installed, You can use
      Use “Import-Module Microsoft.Online.SharePoint.PowerShell”, instead of referencing DLL files.

      Reply
  • There seems to be a lot of people still stuck unable to turn off the forced docLib versioning. Thanks for sharing this!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *