Answers for "SharePoint Online Script to enable versioning"

0

SharePoint Online Script to enable versioning

#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-SPOVersioning()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName
    )
    Try {
        #Setup Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
          
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
         
        #sharepoint online powershell enable versioning
        $List.EnableVersioning = $True
        $List.MajorVersionLimit = 50
        $List.Update()
        $Ctx.ExecuteQuery() 
        Write-host -f Green "Versioning has been turned ON at $ListName"
  
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
 
#Set Parameters
$SiteURL="https://crescenttech.sharepoint.com"
$ListName="Projects"
 
#Call the function 
Enable-SPOVersioning -SiteURL $SiteURL -ListName $ListName
Posted by: Guest on September-02-2021

Browse Popular Code Answers by Language