SharePoint Online: Configure Require Check Out Option using PowerShell
Requirement: Configure the require check out settings in SharePoint Online.
The Require check out option in SharePoint Online helps to avoid save conflicts when multiple users attempt to open and edit a document simultaneously. 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:
- Navigate to your SharePoint Online document library.
- Click on Settings gear >> choose “Library Settings”
- On the Document Library Settings page, Click on Versioning settings
- Scroll down to the bottom of the page. Under Require Check out the section, select “Yes” for the “Require documents to be checked out before they can be edited?” option to enable check out. Similarly, to disable check out in SharePoint Online, select the “No” option.
- 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 a 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://Crescent.sharepoint.com"
$RequireCheckout = $True
#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 $RequireCheckout
How to Disable Check out in SharePoint Online?
If the “Require checkout” option is already enabled for a document library, we can disable it in bulk for all libraries in a site collection with this PnP PowerShell script.
#Function to Disable Checkout Option for all libraries in a web
Function Disable-PnPRequireCheckout
{
param
(
[parameter(Mandatory = $true, ValueFromPipeline = $True)]$Web
)
Try {
Write-host "Processing Web:"$Web.URL -f Magenta
Connect-PnPOnline -Url $Web.URL -Interactive
#Array to exclude system libraries
$SystemLibraries = @("Form Templates", "Pages", "Preservation Hold Library","Site Assets", "Site Pages", "Images",
"Site Collection Documents", "Site Collection Images","Style Library","Drop Off Library")
$Libraries = Get-PnPList -Includes BaseType, Hidden, EnableVersioning -ErrorAction Stop
#Get All document libraries
$DocumentLibraries = $Libraries | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False -and $_.Title -notin $SystemLibraries}
#Disable Checkout
ForEach($Library in $DocumentLibraries)
{
If($Library.ForceCheckout)
{
#Powershell to disable checkout for the library
Set-PnPList -Identity $Library -ForceCheckout $false
Write-host -f Green "`tRequire Check-out disabled on '$($Library.Title)'"
}
Else
{
Write-host -f Yellow "`tRequire Check Out is already set to 'No' at '$($Library.Title)'"
}
}
}
Catch {
Write-host -f Red "`tError:" $_.Exception.Message
}
}
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to PnP Online
Connect-PnPOnline -URL $SiteURL -Interactive
#Call the function for each web
Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object { Disable-PnPRequireCheckout $_ }
Here is another article discussing setting up Require check out option in SharePoint: Configure Require Check Out in SharePoint
When adding a document to the Library from Onedrive, it is already checked-in, is this something that can be forced to be checked out as well?