Check In All Documents in a SharePoint Library using PowerShell

Requirement: Check in All files that are checked out in a SharePoint document library.

How to Check In all checked out documents in SharePoint 2016?

SharePoint 2016 makes it simpler by providing context-sensitive ribbon buttons to check in multiple files in bulk. Simply select all checked files and click on the “Check In” button from the ribbon.

check in multiple documents in SharePoint 2013

But this method doesn’t work when you have any required field with no default value assigned!

Check In All Documents in a SharePoint Library using PowerShell

When you do Multiple file upload (bulk upload or through explorer view), and your required column doesn’t have any default value, your files will be checked-out automatically. The “Check In” button won’t work when you miss out on any required fields in the library.

You must fill out all required properties before checking in this document.

So, our solution is: PowerShell!

PowerShell script to check in all documents in the library:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for Site URL and Library Name
$WebURL="https://sharepoint.crescent.com/sites/sales"
$LibraryName="Proposal Documents"

#Get Site and Library
$Web = Get-SPWeb $WebURL
$DocLib = $Web.Lists.TryGetList($LibraryName)

#Get all Checked out files
$CheckedOutFiles = $DocLib.Items | Where-Object { $_.File.CheckOutStatus -ne "None"} 

#Check in All Checked out Files in the library
ForEach($item in $CheckedOutFiles)
{ 
    #If you want to update fields
    #$item["Field"] = "value"
    #$item.SystemUpdate()
 
    #check in file programmatically     
    #$item.TakeoverCheckout() 
    $DocLib.GetItemById($item.Id).file.CheckIn("Checked in by Admin") 
    write-host "File:'$($item.Name)' has been checked in!"        
}

If you want to do this for all libraries in your entire SharePoint web application, use: Find All Checked Out Files and Check-In them Back

It’s possible to check in file without supplying required field values through PowerShell!

To bulk check-in multiple files in SharePoint Online using PowerShell, use: SharePoint Online: Check In Multiple Files using PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

7 thoughts on “Check In All Documents in a SharePoint Library using PowerShell

  • This script not work, any help

    Thank you.

    Reply
    • Error is:
      Get-SPWeb : The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
      that the path is correct and try again.
      At line:8 char:8
      + $Web = Get-SPWeb $WebURL
      + ~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

      You cannot call a method on a null-valued expression.
      At line:9 char:1
      + $DocLib = $Web.Lists.TryGetList($LibraryName)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

      Reply
    • Make sure you added “Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue” in Line#1 and you are running this script in any of the SharePoint On-premises server (and not from your client machine!)

      Reply
  • Hi Salauden,

    How to take ownership and checkin from “Manage files which have no checked in version” through powershell in particular library?

    Could you please help on this.

    Thank you.

    Reply
  • Can this be inserted as a link, so the current user could check in all files with one click?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *