Skip to content

Enhancement: Add fields and filters to 'spo folder list' #4659

@martinlingstuyl

Description

@martinlingstuyl

The spo listitem list has some useful features that are not available on spo folder list

As a user, I want to:

  • be able to select specific fields
  • be able to use filters
    (additional: - request folders in a library that contains more than 5000 items)

We need the following options to make this work:

Option Description
--fields [fields] Comma-separated list of fields to retrieve. Will retrieve all fields if not specified and json output is requested.
--filter [filter] OData filter to use to query the list of items with.

Additional Information

The /folders endpoint has NO nextlink/skiptoken implementation like with listitems. We can implement paging though, using $top and $skip. This is a less solid implementation of paging, but useful nonetheless.

To be able to query all items we also have to refactor the endpoint that is used and move from the current $expand setup to using /folders.

The following steps should be taken:

  1. Query GetFolderByServerRelativePath(decodedurl='<folder>')?$expand=Properties&$select=Properties/vti_x005f_folderitemcount,Properties/vti_x005f_foldersubfolderitemcount on the root folder that is coming in through the options.

  2. Next, use GetFolderByServerRelativePath('somefolder')/Folders endpoint to query all folders directly below, with $skip and $top. (Default $take to 5000) Use the Properties to calculate how many calls you need to do here.

  3. When the recursive flag is set, restart step 1-2 on every subfolder coming in from the /Folders calls.

Important: Use the --filter option value for all /Folders calls.

When the --fields option includes values with a /, for example: ListItemAllFields/Id, an additional $expand query parameter should be included on ListItemAllFields.

When the --fields option includes values with a /, for example: ListItemAllFields/Id, an additional $expand query parameter should be included on ListItemAllFields.

Originally posted by @martinlingstuyl in #4654

Additional change: just like with spo listitem list, the spo folder list command now supports retrieving the ID of the listitem. This can be problematic in PowerShell when using the ConvertFrom-Json commandlet, because the ListItemAllFields object has an Id and ID property that are the same except the casing. PowerShell can't handle this. Just like with spo listitem list, we've implemented this to remove the ID property if it is available.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions