CheckInScriptoLIBRARY

sns 9,246 Reputation points
2020-11-03T15:26:32.943+00:00

I have attached script which works to check in files in the library which are already checked out in that library.

If library contains folders inside the folders and nested folder which are having check out files, This script is not able check in those files.

And at the end I should know how many files have been checked in with file name after executing the amended script.

Please help.

FYI: our library has 65000 files which are checked out. Thank you37194-checkinfilesinlibrary.txt

Microsoft 365 and Office SharePoint Server For business
{count} votes

Accepted answer
  1. Sharath Kumar Aluri 3,071 Reputation points
    2020-11-03T15:54:26.923+00:00

    Try with the below sample script:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    
    #Variables
    $WebURL="http://portal.globalsp.com"
    $ListName="Documents"
    
    #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>
                          <IsNotNull>
                            <FieldRef Name='CheckoutUser' />
                          </IsNotNull>
                        </Where>"
        $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!"
        }
    }
    else
    {
        Write-Host -f Yellow "List '$ListName' Does not Exist!"
    }
    

    https://www.sharepointdiary.com/2013/02/find-all-checked-out-files-and-check-in.html

    Thanks & Regards,


1 additional answer

Sort by: Most helpful
  1. ZhengyuGuo 10,586 Reputation points Moderator
    2020-11-04T02:12:17.637+00:00

    Hi @sns ,

    Please check sharatha's PowerShell script, it's able to find checked out files in nested sub folder and check it in:

     Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
             
     #Variables  
     $WebURL="http://sp/sites/MyDev"  
     $ListName="Documents"  
            
     #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>  
                           <IsNotNull>  
                             <FieldRef Name='CheckoutUser' />  
                           </IsNotNull>  
                         </Where>"  
         $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!"  
         }  
     }  
     else  
     {  
         Write-Host -f Yellow "List '$ListName' Does not Exist!"  
     }  
    

    37321-snipaste-2020-11-04-10-11-04.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.