0

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?

1 Answer 1

0

Duh...

I moved the filter inside the foreach loop to process only the specified DocLib, like so:

$lists = $web.Lists

foreach ($list in $lists)
{
    if (($libCode -ne "All") -and ($list.Title -ne $libName)) { continue }

    $context.Load($list)
    $context.Load($list.RootFolder.Folders)
    $context.ExecuteQuery();

    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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