I am trying to grab a specific list, and then read through the items in the list one by one, I tried a count but this does not work as a count is just a number of found entries where the ID may not be the same.

$web = get-spweb https://sp.test.com/site1/

foreach($site in $web.Site.Allwebs)
if($site.Url -like '*sites1/SecureSp/*')    {
$lists = $site.Lists
    foreach($list in $lists)

        if($list.Title -like 'Info')
            $siteForList = get-spweb $site.Url

            # Get Iternal Field Names For List Start 
            $StatusItems = $siteForList.Lists['info']           
            # Get Iternal Field Names For List End 

            $listItemsCount = $caseStatusItems.ItemCount

                for($i = 1; $i -le $listItemsCount; $i++)

                        $listItem = $item.GetItemByID($i)
                        if($listItem["Created"] -like '*5/18/2017*' -OR $listItem["Created"] -like '*5/17/2017*')

                        write-host "----------------------------------------------------------------------------------------------------" -foregroundcolor red
                        write-host "URL: " -foregroundcolor green 
                        write-host "Subject: " -foregroundcolor green
                        write-host "Created By: " -foregroundcolor green 
                        $listItem["Created By"] 
                        write-host "Created: " -foregroundcolor green
                        write-host "Last Updated: " -foregroundcolor green
                        $listItem["Last Updated"] 
                        write-host "ID: " -foregroundcolor green
                        write-host "----------------------------------------------------------------------------------------------------" -foregroundcolor red




1 Answer 1


You don`t have to get the count to loop through all the list items. You can use below syntax

$listItems = $caseStatusItems.Items
$listItems | ForEach-Object {
    Write-Host $_['ID']
    Write-Host $_['Title']
foreach($oItem in $listItems) {
   Write-Host $oItem.Title

You can also get the filtered list items using caml query. The syntax as follows

$query = New-Object Microsoft.SharePoint.SPQuery
$caml = 'caml query';
$query.Query = $caml

$listItems = $caseStatusItems.GetItems($query);

You can refer this article for an example

  • I am trying this but I am getting nothing aside from a blank screen. Maybe it is worth noting I am using SP 2010. Commented May 22, 2017 at 18:22
  • It should work for SP2010 and above versions. I hope you are running from the SP server and sufficient rights. I have updated the answer with additional syntax. Commented May 22, 2017 at 18:28
  • Do you mean filter multiple columns or select multiple columns? Commented May 22, 2017 at 18:37
  • Nevermind got it, I could do $item["Field Name Here"]. Thanks again! Commented May 22, 2017 at 18:38
  • Great Explanation @VenkatKonjeti! We really appreciate this detailed formatted answer with Ref! but we have noted that you didn't use any upvote till now, hope to use it in case you find any helpful answer or awesome question Thank you so much for your valuable effort :) Commented May 31, 2017 at 17:29

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.