I retrieved all items in my SharePoint list using .GetItems()
command.
However, it does not have contain folder type
items in my result.
A type of ERMS Folder Content Type
do exists in the list, as below:
Documents of other content types are still being displayed, no issues.
May I know if I have used the incorrect commands to retrieve folders in a SharePoint list?
Below is my code snippet:
$baseUrl = "http://test.com"
$web = Get-SPWeb($baseUrl)
$RDlistUrl = $baseUrl + "/RecordsDocument"
$RDlist = $web.GetList($RDlistUrl)
$RDitems = $RDlist.GetItems()
foreach ($RDitem in $RDitems)
{
if ($RDitem.ContentType.Name.Contains("Folder"))
{
//no output captured.
}
splist.GetItems()
would not get folder items. You have to use splist.folders
to get folder items : https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ms443958(v=office.14)
Please change your code to this:
#Get folder items
$RDitems = $RDlist.Folders
foreach ($RDitem in $RDitems)
{
if ($RDitem.ContentType.Name.Contains("Folder"))
{
$RDitem
}
}