How to fetch Immediate files and folders of Parent folder?

Hsaniba 100 Reputation points
2024-04-25T10:20:02.02+00:00

I want fetch folders and files immediate to the parentStructure

The above is the Structure of a list in the SharePoint online(There are more lists similar like this).

First, I want to fetch Folder1, Folder2 and all 35000 files in the hierarchy level 1 which is immediate to the List 1.

After that I have to go every folder's immediate child items that is level 2. First I take Folder1 which is fetched from List1 previously and Fetch immediate items like F1, F2, F3 and all 34000 files in that level. Then I take F1 and fetch immediate items like C1, C2 and all 5000 files. After that I take f2 but that is empty. Then I take F3 and fetch C3, C4 and all 5000 files.

Then I go to Folder 2 and Fetch it's immediate items and so on(recursively).

This is the way I am going fetch files and folders immediate to the parent folders.

I am searching for proper cmdlet which fetch faster and efficient. I'm using "Get-PnPListItem -List $List -PageSize 2000 | where {$_.FieldValues.FileDirRef -eq $Item.FieldValues.FileRef}", This fetches correctly but very slowly while working with large sites consisting of 50,000 files and more.

So, I need a proper cmdlet which fetches files and folders immediate to the parent quickly.

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,227 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,675 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yanli Jiang - MSFT 21,611 Reputation points Microsoft Vendor
    2024-04-26T09:26:48.27+00:00

    Hi @Hsaniba ,

    As far as I know, using PnP PowerShell is already the fastest way, and there is nothing faster than this. If you feel it is slow, it may be because there are too many files to be traversed. It is recommended that you reduce this situation during use.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments