I want fetch folders and files immediate to the parent
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.