In Powershell i get all checked out file from a library with

foreach($f in $lib.CheckedOutFiles){
    //I tried to retrieve item with 
    $item = $lib.GetItemById($f.ListItemID)//exception item not retrieve

How can i checkin spcheckedoutfile?


I finally found a solution. For having item i have to do a TakeOverCheckOut before and after i can have item and file to checkin

foreach ($item in $lib.CheckedOutFiles) {
    write-Host $item.ListitemId
    $item.TakeOverCheckOut()//to retrieve item i have to do this before
    $doc = $lib.getItemById($item.ListitemId)
    $itemFile = $doc.File
    if($itemFile -ne $null){
        $itemFile.CheckIn("Checked In By Administrator for achive")
        write-Host " Checked In" -ForeGroundColor Green


1 Answer 1


To check-in all files within a specific library, try this

$spWeb = Get-SPWeb http://yoursite/
$splist = $spWeb.Lists |? {$_.Title -eq "libname"}
foreach ($item in $splist.Items) 
    if( $item.File.CheckOutStatus -ne "None" )

Check also how to checkin all checked out files via powershell?

  • Thanks but with this method you don't have files that has not yet checked in Oct 9, 2016 at 12:24
  • I am sorry , but what I understand from you , you need to check in all checked out files , should you elaborate more what you need specifically , to can help you :) ? Oct 9, 2016 at 13:17
  • 2
    Yes i use your solution for file already checked in in library but files that are not yet in library is not in items of library. You have to use .CheckedOutFiles. Oct 9, 2016 at 19:47
  • Great job, thanks for this info :) , forgive me I think I didn't understand your question correctly at the first :) , So I answered based on this line in your quest I get all checked out file from a library to check in Oct 9, 2016 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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