SharePoint 2013 PowerShell: How to Check in the multiple Documents in the SP library

Today we got a requirement about how to check in the multiple documents in a document library which enables "Require Check Out" setting.

Question

Lots of Documents are checked out after they are synced to SharePoint Library which enables "Require Check Out" Setting, Since these Documents are stored in the different folders, it is hard to check in them at one time.

Solution

Check in the Documents in the library with SharePoint PowerShell.

Please refer to the demo script below:

Variables for Site URL and Library Name: Open SharePoint PowerShell and run it as the Administration, type the following cmdlet:

$WebURL="http://cpshelley:9001/sites/Project_Shelley"
$LibraryName="shelley"

Type the following cmdlet to Get Site and Library:

$Web = Get-SPWeb $WebURL
$CheckedOu$DocLib = $Web.Lists.TryGetList($LibraryName)

Type the following cmdlet to Get all Checked out documents:

$CheckedOutFiles = $DocLib.Items | Where-Object { $_.File.CheckOutStatus -ne "None"}

Type the following cmdlet to Check in all the Checked out documents in the library:

ForEach($item in $CheckedOutFiles) { $DocLib.GetItemById($item.Id).file.CheckIn("Checked in by cp01\administrator") }