[BUG] Unable to export folders from PictureLibrary recursively AND with security using Add-PnPListFoldersToProvisioningTemplate
Notice
Many bugs reported are actually related to the PnP Framework which is used behind the scenes. Consider carefully where to report an issue:
- Are you using
Invoke-PnPSiteTemplateorGet-PnPSiteTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/pnp/pnpframework/issues. - Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
- If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/powershell/tree/master/src/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/pnp/pnpframework/issues
Reporting an Issue or Missing Feature
Please confirm what it is that your reporting
- Issue
Expected behavior
- When exporting folders from a PictureLibrary using
Add-PnPListFoldersToProvisioningTemplate, I would expect to be able to use both the available parameters-Recursiveand-IncludeSecurity
Actual behavior
- When exporting folders from a PictureLibrary using
Add-PnPListFoldersToProvisioningTemplateusing both the available parameters-Recursiveand-IncludeSecurity, and error is throw immediately if any folder is present with contents in the library.
Error:

Screenshot of PictureLibrary

Steps to reproduce behavior
- Create new SharePoint site
Connect-PnPOnlineNew-PnPList -Title Images -Template PictureLibrary- Add a folder to newly created library
- Place some images in newly created folder
Get-PnPProvisioningTemplateAdd-PnPListFoldersToProvisioningTemplate -List Images -Recursive -IncludeSecurity
What is the version of the Cmdlet module you are running?
- Issue was first detected in module SharepointPnPPowerShellOnline 3.19.2003.0
- Tested and still present in PnP.PowerShell 1.7.0
Which operating system/environment are you running PnP PowerShell on?
- [X] Windows
@umaknow-william - what is the current error that you are getting when using the latest module ? The screenshot looks to be from the old module.
Yes, sorry, the screenshots where taken with an earlier version. Here is a screenshot using the current version, (same process) the behavior is the same, I believe because the code in the C# class is the same

One more question, what is the site template from which you are getting this PnP template? Is it communication site or team site or something else ?
Communication sites, I haven't tested it with a Team site.