Find All Checked Out Files and Check-In them Back using PowerShell

I’m Sharing one of the PowerShell script I used in SharePoint 2010 migration. Since its very difficult to check-in back all the checked-out files after migration, its a best practice to check-in all checked out files prior.

Find All Checked-Out files and Check in back in a SharePoint Library using PowerShell:

Let’s find all checked out files in a SharePoint library of folder and check them in back!

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$LibraryURL="/Shared%20Documents" #Relative URL of a folder or library

#Get Objects
$Web = Get-SPWeb $WebURL
$Folder = $web.GetFolder($LibraryURL)

#Function to find all checked out files in a SharePoint library
Function CheckIn-CheckedOutFiles($Folder)

    $Folder.Files | Where { $_.CheckOutStatus -ne "None" }  | ForEach-Object {
    write-host ($_.Name,$_.URL,$_.CheckedOutBy)

    #To Check in
    $_.Checkin("Checked in by Administrator")

   #Process all sub folders
   $Folder.SubFolders | ForEach-Object {
   CheckIn-CheckedOutFiles $_

#Call the function to find checkedout files
CheckIn-CheckedOutFiles $Folder 

While this works fine, lets improve the performance by filtering checked out documents using CAML query:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get Objects
$Web = Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)
If($List -ne $Null)
    #Define CAML query to filter all checked out files
    $Query = New-Object Microsoft.SharePoint.SPQuery
    $Query.Query = "<Where>
                        <FieldRef Name='CheckoutUser' />
    $Query.ViewAttributes = 'Scope="Recursive"'
    $ListItems = $List.GetItems($Query)
    Write-host "Total Number of Checked Out Files Found:"$ListItems.count

    #Loop through each checked out File
    ForEach ($Item in $ListItems) 
        Write-Host "'$($Item.Url)' is Checked out by: $($Item["CheckoutUser"])"

        #Check in
        #$Item.File.CheckIn("Checked in By Administrator!")
        #Write-Host -f Green "File Checked In!"
    Write-Host -f Yellow "List '$ListName' Does not Exist!"

PowerShell to Find All Checked Out Files and Check-in from a Web Application

This PowerShell script will scan, generates reports, and check in all checked-out files. Run this script with Farm Administrator privileges.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function CheckIn-AllCheckedOutFiles()
    #Define 'Web Application URL' as Mandatory Parameter
    [Parameter(Mandatory=$true)] [string]$WebAppURL,
    [Parameter(Mandatory=$true)] [string]$ReportOutput 
    #Get the Web Application
    $WebApp = Get-SPWebApplication $WebAppURL

    #Write the CSV Header - Tab Separated
    "Site Collection Name `t Site Name`t Library `t File Name `t File URL `t  Last Modified `t Checked-Out By" | Out-file $ReportOutput

    #Arry to Skip System Lists and Libraries
    $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates", "List Template Gallery", "Theme Gallery", 
           "Reporting Templates", "Solution Gallery", "Style Library", "Web Part Gallery","Site Assets", "wfpub")
    #Loop through each site collection
    ForEach($Site in $WebApp.Sites)
        #Loop through each site in the site collection
        ForEach($Web in $Site.AllWebs)
            Write-host "Processing Site:" $web.Url
            #Loop through each document library
            Foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
                #Get only Document Libraries & Exclude Hidden System libraries
                if ( ($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
                    #Loop through each Item
                    foreach ($ListItem in $List.Items) 
                        If( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
                            #Log the data to a CSV file
                            "$($Site.RootWeb.Title) `t $($Web.Title) `t $($List.Title) `t $($ListItem.Name) `t $($Web.Url)/$($ListItem.Url) `t  $($ListItem['Modified'].ToString()) `t  $($ListItem.File.CheckedOutByUser)" | Out-File $ReportOutput -Append
                            Write-host -f Yellow "Found a Checked out file at: $($Web.Url)/$($ListItem.Url)"
                            #Check in the file
                            $ListItem.File.Checkin("Checked in by Administrator")
    #Send message to output console
    write-host -f Green "Checked out Files Report Generated Successfully!"

#Call the Function to Get Checked-Out Files and check them in
CheckIn-AllCheckedOutFiles -WebAppURL "" -ReportOutput "C:\Temp\CheckedOutFiles.txt"
Its also possible to retrieve all checked out files via Search! Here is how: Create a Managed Property by adding the existing crawled property: ows_CheckoutUser(Text), then you can use that managed property in your search!

Bulk Check-In all checked-out files in the Site collection:

If you want to check in all checked-out files by you, use “Content and Structure” link under site settings. (/_Layouts/sitemanager.aspx)

Bulk Check-in Files in SharePoint

You have the option “Checked Out to Me” which lists all files checked-out to you. Just select the desired files and click Check-in from actions menu.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

6 thoughts on “Find All Checked Out Files and Check-In them Back using PowerShell

  • Hi there! I so happy I found this script. I need to check in 25,000 documents at one time. However, when I run this script. It tells me “no snap-ins have been registered for windows powershell version 5”. When I tried to research this error there SO much information regarding fixing it but none seem to work.

  • It appears to run but doesn’t. It creates the text file and creates the headers for it. And it seems to be processing something but it never finds any checked out files and I know I have a ton of them. Not sure what I am missing

    • Make sure you are running this script from FARM Admin Credentials, which should be granted with “FULL Control” User Policy to your target web application.

    • Getting the same problem. Tried it with both a farm admin account (my own) and the actual farm installation account, and both have the same result. Script appears to run for a few minutes then outputs a report with only the headers.

  • Hi
    thanks for the information but it helps to checkout all files while doing migration from 2007 to 2010.
    my situation is in Sp 2010 user had left the organization and we have only one document which was checked out bye that user.can you explain this scenario for me with clear examples because i don’t have scripting knowledge.

    • Surya,

      Sure, just change this line in the script. From:
      if( ($ListItem.File.CheckOutStatus -ne “None”) -and ($ListItem.File.CheckedOutByUser -ne $null))

      if( ($ListItem.File.CheckOutStatus -ne “None”) -and ($ListItem.File.CheckedOutByUser.LoginName -eq “DomainUserName” ))


Leave a Reply

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