1

I am in the process of writing a powershell script to work with checked out files and I stumpled on this article: Find All Checked Out Files

My question is what is the difference between the two sections...

foreach ($item in $list.CheckedOutFiles) {...

and

foreach ($item in $list.Items) {
                if ($item.File.CheckOutStatus -ne "None") {...

At first glance it looks like $list.CheckedOutFiles returns a collection of SPCheckedOutFile where as the second returns SPListItems...

In what scenario would something be a part of $list.CheckedOutFiles and not be part of the second?

My reason for asking is that I would rather only use the SPListItems because they have the properties available to me that I am looking for, but I want to make sure I am not missing something I need....

1 Answer 1

1

The script comes from this site initially:

http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/

It seems that the second loop is made to catch files that are missing in the collection of "CheckedOutFiles". It can be that there are files that never had a check in, meaning the "CheckOutStatus" not equals (-ne) "None". This can happen if you upload files programatically or if files have been uploaded before the requirement of checking in and checking out has been enabled.

See the original text: "One cool thing to point out about this is that it will also show you files that you normally can’t see – that is files that have been created by other users but have never had a check in. This is actually pretty cool and I stumbled upon this when trying to fine tune my Publish-SPListItems cmdlet. You see, if the file has never been checked in then iterating through the SPListItemCollection object will not reveal the item (or file I should say); this meant that my cmdlet, as it was previously written, was missing a bunch of files."

2
  • I get what you are saying but I think you meant it in reverse.... The first loop is for files that were never checked in.
    – BlueBird
    Commented Mar 7, 2013 at 17:03
  • Yep, you are right. It's the other way round. Sorry for the late response.
    – hupseb
    Commented Mar 18, 2013 at 10:32

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.