Monday, January 30, 2017

SharePoint Online: How to Enable Versioning on a Document Library using PowerShell

What is versioning in SharePoint Online?
Version history feature in SharePoint Online tracks every change to the document and creates a copy of it when someone changes a document. Each version of the document has the following:

  • Version No
  • When the version was created
  • Who made the version (change)
  • Size of the version
Once the versioning feature is enabled, you can view/restore the previous versions of the document.

How to Enable Version History in SharePoint Online Document Library?
To Enable or Disable Versioning in SharePoint Online Document Library:
  • Navigate to your document library >> Click on Settings gear >> and then "Library Settings" Menu item.
  • Under Library settings page, Click on "Versioning Settings"
  • Select "Create major versions" option and enter number of versions to track (by default, this is enabled with 500 versions in SharePoint Online). sharepoint online powershell to enable versioning in document library
  • Scroll to the bottom of the page. Click "OK" to apply versioning setting changes.

SharePoint Online: PowerShell to enable versioning in document library
#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 Enable-DocLibraryVersioning()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $DocLibraryName
    Try {
    #Setup Credentials to connect
    $Cred = Get-Credential
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the Library from the web
    $Library = $Ctx.Web.Lists.GetByTitle($DocLibraryName)

    #enable versioning in sharepoint online
    $Library.EnableVersioning = $True
    $Library.MajorVersionLimit = 50

    write-host  -f Green "Version History Enabled for Document Library!"
    Catch {
        write-host -f Red "Error enabling versioning in Document Library!" $_.Exception.Message

#Set Parameters
$SiteURL= ""
$DocLibraryName="Project Docs"

#Call the function to enable versioning in document library
Enable-DocLibraryVersioning -siteURL $SiteURL -DocLibraryName $DocLibraryName

To Enable version history on all lists and libraries, use: 
SharePoint Online: Enable Versioning on All List and Libraries using PowerShell

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...