Skip to content

Enhancement: Add fields, filters to 'spo file list' #4654

@martinlingstuyl

Description

@martinlingstuyl

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

As a user, I want to:

  • be able to select specific fields
  • be able to use filters
    (additional: - request files 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 /files 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 /files and /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')/Files endpoint to query all files 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, use GetFolderByServerRelativePath('somefolder')/Folders to get the subfolders. Use $skip and $top here as well. Use the Properties to calculate how many /Folders calls you need to do here.

  4. Next, restart step 1-3 on every subfolder coming in from the /Folders calls.

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

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

Additional change: just like with spo listitem list, the spo file 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