How to Enable Versioning in Document Library in Sharepoint online Powershell?

Hello SharePointers,

Below is the powershell code to enable verisoning in all Document Libraries in a Web in SharePoint online.

$context=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$context.Load($context.Web.Lists)
$context.Load($context.Web)
$context.Load($context.Web.Webs)
$context.ExecuteQuery()

Write-Host $ctx.Url -BackgroundColor White -ForegroundColor DarkGreen
foreach( $list in $context.Web.Lists)
{

if ($list.BaseType -eq “DocumentLibrary”) {
$list.EnableVersioning = $true
$list.Update()
}

Happy Sharepointing 🙂

Leave a Reply

Your email address will not be published.