I want to get all the files from the root folder and its sub-folders, now when I tried this script:

$customerFolderFiles = Get-PnPFolderItem `
  -FolderSiteRelativeUrl $serverRelativeUrl `
  -Recursive `
  -ItemType File

this will not get the files inside the sub-folders and will only get the files inside the root folder, any fix for this?



1 Answer 1


The script will get all the items first, then do the filter. In your case the cmdlet is like following

$CustomerFolders = $var | where {
  $_.FieldValues.FileDirRef -eq $MainfolderUrl -and 
  $_.FileSystemObjectType -eq 'Folder'

$var is the collection of items. The script get all the items in $var then where clause filters the data.

  • How do you get the collection of all items into $var?
    – Dennis
    Commented Apr 9 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.