On Sharepoint Online, using a Powershell/CSOM console app, in a Site Collection with 34 DocLibs, I need to extract a listing of DocLib Items and their attributes.
I want to allow the user to specify either 'All' DocLibs, or a specific DocLib using a Program Code (i.e. 'LCL', for 'LCL Library').
My Question: How do I loop through all Lists in a ListCollection if the user enters 'All', but 'loop' through only the LCL Library if the user enters 'LCL'?
One idea I had was to remove the 'extra' Lists from the ListCollection when a single DocLib is entered, which it looks something like this:
$lists = $web.Lists
if ($libCode -ne "All")
{
foreach($list in $lists)
{
if($list.Title -ne $libName)
{ $lists.RemoveChild($list) }
}
}
foreach ($list in $lists)
{
$context.Load($list)
$context.Load($list.RootFolder.Folders)
$context.ExecuteQuery();
...
}
This approach errors with the following:
Method invocation failed because [Microsoft.SharePoint.Client.List] does not contain a method named 'RemoveChild'.At C:\Users\thebear\Desktop\SEDA\SEDAGetItemData.ps1:46 char:11 + { $lists.RemoveChild($list) }
Is there another way to achieve this?