How do I get all of the subfolders in a folder using PnP PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-95749%22%20slang%3D%22en-US%22%3EHow%20do%20I%20get%20all%20of%20the%20subfolders%20in%20a%20folder%20using%20PnP%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-95749%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20do%20I%20use%20the%20PnP%20PowerShell%20to%20get%20all%26nbsp%3Bof%20the%20subfolders%20in%20a%20folder%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-96617%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20get%20all%20of%20the%20subfolders%20in%20a%20folder%20using%20PnP%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-96617%22%20slang%3D%22en-US%22%3E%3CP%3ESince%20you%20already%20seem%20to%20have%20the%20root%20folder%20object%20(%24folder)%20that%20you%20want%20(and%20assuming%20that%20all%20context%20and%20what%20not%20are%20properly%20in%20place%20in%20your%20script)%2C%20it%20probably%20looks%20something%20like%20this%3A%3C%2FP%3E%3CPRE%3E%24subfolders%20%3D%20Get-PnPProperty%20-ClientObject%20%24folder%20-Property%20Folders%3C%2FPRE%3E%3CP%3E...at%20which%20point%20you%20can%20iterate%20through%20%24subfolders%20to%20do%20whatever%20you%20need%20to%20do.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

How do I use the PnP PowerShell to get all of the subfolders in a folder ?

1 Reply

Since you already seem to have the root folder object ($folder) that you want (and assuming that all context and what not are properly in place in your script), it probably looks something like this:

$subfolders = Get-PnPProperty -ClientObject $folder -Property Folders

...at which point you can iterate through $subfolders to do whatever you need to do.

 

Hope that helps.