Skip to content

[BUG] Recursive flag for Get-PnPFolderInFolder doesn't work on root site #5068

@Toonshorty

Description

@Toonshorty

Reporting an Issue or Missing Feature

When calling the Get-PnPFolderInFolder command with the -Recursive flag from the root site collection of the SharePoint tenant, only the immediate child folders are returned. I believe this is due to the way in which the relativeUrl variable is being calculated on GetFolderInFolder.cs:161 as for the root site, the value of CurrentWeb.ServerRelativeUrl is "/". This results in all slashes from the target folder's ServerRelativeUrl property being removed.

Expected behavior

The command should recursively iterate through all folders and subfolders.

Actual behavior

The command exclusively returns the immediate child folders. When enabling verbose logging, the command shows an incorrect path in the 'Processing folder' trace log. If given a library with the name 'ExampleLibrary' containing a folder named 'TestFolder' which in turn contains a subfolder named 'TestSubfolder01', the expected output would be 'Processing folder ExampleLibrary/TestFolder/TestSubfolder01', but instead 'Processing folder ExampleLibraryTestFolderTestSubfolder01' is displayed instead.

Steps to reproduce behavior

  1. If no suitable test list exists, create a new library in the root site collection of the tenant and add a hierarchy of folders. For this example there a folder called 'TestFolder' is created at the root of the library and another folder named 'TestSubfolder01' is created within this.
  2. Connect to the root site collection of a SharePoint tenant (e.g. Connect-PnPOnline -Url https://contoso.sharepoint.com)
  3. Call Get-PnPFolderInFolder on the test library with the -Recursive flag:
Get-PnPFolderInFolder -Identity 'ExampleLibrary' -Recursive -Verbose
  1. Observe that the script returns the 'TestFolder' folder but does not return 'TestSubfolder01' and that the path shown in the trace logs or verbose output is 'ExampleLibraryTestFolderTestSubfolder01'

What is the version of the Cmdlet module you are running?

3.1.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions