0

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?

SOLUTION

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
    }

}

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

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" )
    { 
        $item.File.CheckIn("Checkedin")
    }
}
$spWeb.Dispose()

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 – user1898765 Oct 9 '16 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 :) ? – Mohamed El-Qassas MVP Oct 9 '16 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. – user1898765 Oct 9 '16 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 – Mohamed El-Qassas MVP Oct 9 '16 at 19:56

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.