We want to force check-in all the documents at "site collection level" i.e from all its sub-sites and all document library. Would need help on a powershell script which can do the same.

BR/ Somesh


The following PowerShell Script will check in all checked out files on the specified site collection. It iterates each web in the site collection, gets all lists of type DocumentLibrary (not hidden), gets all checked out files, and checks each one in.

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$siteUrl = "http://yoursharepointsite"
$webs = (Get-SPSite -Identity $siteUrl).AllWebs
ForEach ($web in $webs) {
    $libs = $web.GetListsOfType(1)
    ForEach ($lib in $libs | ? { $_.Hidden -eq $false }) {
        $files = $lib.CheckedOutFiles
        ForEach ($file in $files) {
            $f = $web.GetFile("/" + $file.Url)
            $f.CheckIn("Checked in by System")
            Write-Host -ForegroundColor Green "File: $($file.Url) checked in!"

Hope this helps!

|improve this answer|||||
  • 1
    This script is the real McKoy!!! Works like a charm... – L. James Jan 8 '19 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.