I am trying to iterate over a List and view properties on some items that live within that list, and down one or two levels; this is on a SharePoint 2010 server. So far I have been able to connect to the site and iterate over the Folders and the Items in the top level, but what I want is to be able to iterate over items within the Folders. Out structure is as follows:
site - http://localhost/my_site list - Pages Folder - News ItemB - Article ItemA - Contents
The site is easy enough to connect to, with that I can get the list, Folder and ItemA's and output them so I can see what lives there. What I would like is to be able to view all the ItemB's (and there may be lots of them) under each Folder, there are about 10 Folders in the List with each Folder containing lots of ItemB's.
What's the easiest way to be able to find the Folder and then search under the Folder and get all of its Items to display? My experience with PowerShell and SharePoint in this regard is kind of limited. Any helpful pointers are appreciated.
Here is what I have so far, I'd like to have the part that outputs Content to note the ItemB's.
[string]$url = "http://localhost/my_site"
$totalCount = 0
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$list = $web.Lists["Pages"]
foreach ($folderItem in $list.Folders)
{
Write-Host "Folder: " $folderItem.Name "Count: " $folderItem.Folder.ItemCount
$totalCount += $folderItem.Folder.ItemCount
}
foreach ($listItem in $list.Items)
{
Write-Host " Content: " $listItem.Name " Folder: " $listItem.Parent
}
Write-Host "Total Items = " $totalCount
$totalFolders = $list.Folders.Count
Write-Host "in a Total Folders of: " $totalFolders
$site.Dispose()