SharePoint Online: Configure Require Check Out Option using PowerShell

Requirement: Configure require check out settings in SharePoint Online.

Require check out option in SharePoint Online helps to avoid save conflicts when multiple users attempts to open and edit a document at the same time. Basically the Check out is a quick way to lock a document from editing by other users.

How to Enable Require Check Out for Document Libraries in SharePoint Online?
By default, the require checkout option is turned OFF. We can turn require check out option for a document library ON or OFF. Here is how:
  • Go to your SharePoint Online document library.
  • Click on Settings >> Library Settings
  • On Document Library Settings page, Click on Versioning settings
  • Scroll down to the bottom of the page. Under Require Check out section, select Yes for Require documents to be checked out before they can be edited?
    sharepoint online require check out
  • Click "OK" to save your changes.
This Turns on require check out for the document library. What if you want to enable or disable require check out for all document libraries in a SharePoint Online site collection? Well, there is no way to do that from web UI.

PowerShell to Set Require Check Out in SharePoint Online
This PowerShell script enables Require Check out for all document libraries in given site collection in SharePoint Online.
#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 Set-SPORequireCheckout([String] $SiteURL,[Boolean] $RequireCheckout)
{
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
          
        #Get the web and Its subsites from given URL
        $Web = $Ctx.web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Lists)
        $Ctx.Load($web.Webs)
        $Ctx.executeQuery()
  
        #Filter Document Libraries from Lists collection
        $DocumentLibraries = $Web.Lists | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}
 
        Write-host -f Yellow "Processing Site:" $SiteURL
        #Loop through each document library and set require checkout option
        Foreach ($DocumentLibrary in $DocumentLibraries)
        {
            #Require documents to be checked out before they can be edited 
            $DocumentLibrary.ForceCheckout=$RequireCheckout
            $DocumentLibrary.Update()
            $Ctx.ExecuteQuery() 
            Write-host -f Green "`t Require Checkout has been Configured for" $DocumentLibrary.Title
        }
   
        #Iterate through each subsite of the current web
        ForEach ($Subweb in $Web.Webs)
        {
            #Call the function recursively
            Set-SPORequireCheckout $Subweb.url $RequireCheckout
        }
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
 
#Config Parameters
$SiteCollURL="https://crescenttech.sharepoint.com"
$RequireCheckout = $False

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

#Call the function to Set Require Checkout for All document libraries in the site collection
Set-SPORequireCheckout $SiteCollURL $False
Here is my another article discussing setting up Require check out option in SharePoint: Configure Require Check Out in SharePoint
SharePoint Online: Configure Require Check Out Option using PowerShell SharePoint Online: Configure Require Check Out Option using PowerShell Reviewed by Salaudeen Rajack on March 26, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.