Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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....

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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."

share|improve this answer
    
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 Mar 7 '13 at 17:03
    
Yep, you are right. It's the other way round. Sorry for the late response. –  hupseb Mar 18 '13 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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