SharePoint Online PowerShell: Disable versioning in a document library (PnP PowerShell)

In this SharePoint PowerShell tutorial, we will discuss what is versioning in SharePoint? How to disable versioning in SharePoint Online document library using PowerShell and PnP PowerShell.

We will see how to disable versioning using PnP PowerShell also.

I will also show how to enable versioning in a document library in SharePoint using PowerShell and PnP PowerShell.

What is versioning in SharePoint

Versioning is one of the most popular features of the SharePoint Online document library. If you have enabled versioning, then you can store, track changes or modifications, restore changes in the SharePoint list or library.

You can check the changes that you have done and restore them from various previous versions.

In SharePoint Online, by default versioning is OFF for SharePoint lists and ON for SharePoint document libraries.

Also, for OneDriveForBusiness libraries by default versioning is enabled and you can save the latest 500 versions of a document.

no versioning missing in modern SharePoint site

Previously, if you will go to the list or library settings page and then Versioning Settings, then we use to see the below 3 options:

  • No versioning
  • Create major versions
  • Create major and minor (draft) versions

But Microsoft has removed the No Versioning option from document libraries in SharePoint Online sites (classic and modern sites).

No Versioning option has been removed from both the group connected team sites as well as from the team sites not connected to an Office 365 Group.

But No Versioning option is still available in the SharePoint Online communication sites.

no versioning missing in modern sharepoint site
no versioning missing in modern sharepoint site

Disable versioning in SharePoint Online

Now, we will see how to disable versioning in SharePoint Online document libraries.

But as I said in the above photo, the No Versioning option is not available in the SharePoint document libraries, so we can not disable versioning through the browser in SharePoint Online document libraries.

But the option is still available in the SharePoint Online list. You go to List settings -> Versioning Settings. And then select the No option in “Create a version each time you edit an item in this list?”.

turn off versioning in sharepoint online list
disable versioning sharepoint online list

In SharePoint Online, we can now disable versioning using PowerShell.

Disable Versioning in Document Library in SharePoint Online Powershell

Now, we will see how to disable versioning in document library in SharePoint using PowerShell.

Here we will use PowerShell with CSOM to disable versioning. For this, we required the below client-side dlls:

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

If you are trying this PowerShell in Windows 10 OS, then you can download and install SharePoint Online Client Components SDK.

Once you install it, you can get the DLLs from the below directory:

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI

Here, I am using PowerShell ISE to run the below script to disable versioning in SharePoint Online document library.

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"

$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$credentials= Get-Credential
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credentials.Username, $credentials.Password)

$list = $ctx.Web.Lists.GetByTitle("Testing")
$list.EnableVersioning = $False
$list.Update()
$ctx.ExecuteQuery()

Once you execute the above code, it will ask you to enter Office 365 credentials and then you can open the Versioning Settings page to see No Versioning option in the document library.

Disable Versioning in Document Library in SharePoint Online Powershell
turn off versioning in sharepoint online document library

This is how we can disable versioning in SharePoint Online document library using PowerShell.

Enable Versioning in SharePoint Online Document library

In the same way we can also enable versioning in SharePoint Online document library, we need to just change the below line:

$list.EnableVersioning = $True
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"

$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$credentials= Get-Credential
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credentials.Username, $credentials.Password)

$list = $ctx.Web.Lists.GetByTitle("Testing")
$list.EnableVersioning = $True
$list.Update()
$ctx.ExecuteQuery()

Disable versioning for all SharePoint Online document libraries using PowerShell

Now, we will see how to disable versioning of all libraries in SharePoint Online using PowerShell.

You can execute the below code to disable versioning for all SharePoint Online document libraries using PowerShell.


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"

$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$credentials= Get-Credential
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credentials.Username, $credentials.Password)

$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()

$libraries = $lists | Where-Object { $_.BaseType -eq 'DocumentLibrary' }

ForEach($library in $libraries)
{
$library.EnableVersioning = $false
$library.Update()
}

$ctx.ExecuteQuery()

Enable versioning for all SharePoint Online document libraries using PowerShell

In the same way, we can enable versioning for all document libraries in SharePoint Online using PowerShell. We just need to change the below line:

$library.EnableVersioning = $true

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"

$siteUrl = "https://tsinfo.sharepoint.com/sites/TSInfoClassic/"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$credentials= Get-Credential
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credentials.Username, $credentials.Password)

$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()

$libraries = $lists | Where-Object { $_.BaseType -eq 'DocumentLibrary' }

ForEach($library in $libraries)
{
$library.EnableVersioning = $true
$library.Update()
}

$ctx.ExecuteQuery()

This is how we can enable versioning of a document library using PowerShell in SharePoint Online.

Disable versioning in SharePoint Online using PnP PowerShell

Now, we will see how to disable versioning on a document library in SharePoint Online using PnP PowerShell. The same PnP PowerShell script we can use to disable version in SharePoint 2013/2016/2019 also.

If you are new to PnP PowerShell, check out a detailed article on How to connect SharePoint Online using PnP PowerShell.

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/TSInfoClassic/ –Credentials (Get-Credential)
$libraryname="Testing"
Set-PnPList -Identity $libraryname -EnableVersioning $False

After executing the code, if you look at the SharePoint library version settings, you can see the No Versioning option will be reflected.

Disable versioning in SharePoint Online using PnP PowerShell
Disable versioning in SharePoint Online using PnP PowerShell

PnP PowerShell – Enable versioning in document library

Now, we will see how to enable versioning in SharePoint Online document library using PnP PowerShell.

You can write the below PnP PowerShell script:

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/TSInfoClassic/ –Credentials (Get-Credential)
$libraryname="Testing"
Set-PnPList -Identity $libraryname -EnableVersioning $True

Once you run the above code, it will enable create major versions option in SharePoint document library like below:

Enable versioning in document library
Enable versioning in document library

But if you want to enable the minor version (Create major and minor (draft) option) then you can follow the below script. Here you need to add the -EnableMinorVersions $True attribute like below:

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/TSInfoClassic/ –Credentials (Get-Credential)
$libraryname="Testing"
Set-PnPList -Identity $libraryname -EnableVersioning $True -EnableMinorVersions $True

or if you want to define the number of major version and number of minor versions you can write like below:

Connect-PnPOnline –Url https://tsinfo.sharepoint.com/sites/TSInfoClassic/ –Credentials (Get-Credential)
$libraryname="Testing"
Set-PnPList -Identity $libraryname -EnableVersioning $True -EnableMinorVersions $True -MajorVersions 100 -MinorVersions 50
enable minor version sharepoint online using pnp powershell
enable minor version sharepoint online using pnp powershell

This is how we can enable minor version in SharePoint Online document library using PnP PowerShell.

You may like the following tutorials:

I hope this tutorial will help you to learn on versioning in SharePoint as well as how to disable versioning in SharePoint Online document library using PowerShell or PnP PowerShell.

  • What is versioning in SharePoint
  • no versioning missing in modern SharePoint site
  • Disable versioning in SharePoint Online
  • Disable Versioning in Document Library in SharePoint Online Powershell
  • Enable Versioning in SharePoint Online Document library
  • Disable versioning for all SharePoint Online document libraries using PowerShell
  • Enable versioning for all SharePoint Online document libraries using PowerShell
  • Disable versioning in SharePoint Online using PnP PowerShell
  • PnP PowerShell – Enable versioning in document library
  • I get the following error: Exception calling “ExecuteQuery” with “0” argument(s): “The partner returned a bad sign-in name or password error. For more
    information, see Federation Error-handling Scenarios.”
    At line:13 char:1
    + $ctx.ExecuteQuery()
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdcrlException

  • Same – I get the following error: Exception calling “ExecuteQuery” with “0” argument(s):

  • >