SharePoint Online loop and create subfolders

Brass Contributor

Dear all,


I am using a SharePoint Online document library to store documents stored per client.

I have a document set for each client. In total I have more than 500 document sets, all containing the same folder structure.


The document library is built up as follows:

  1. Client A
    1. Invoices
    2. Correspondence
    3. Technical
    4. etc.
  2. Client B
  3. Client C
  4. Client D
  5. etc.


I would like to create another folder at the second level (where Invoices, Correspondence, etc. reside), named "Projects", and inside that new folder just a few subfolders.


I would like to do this automated, otherwise it would take me a lot of time. 

I have seen a few articles on the web, but I haven't found the exact same scenario yet. I know somehow this could be done using PowerShell and a loop? PnP? But I don't have enough knowledge and experience to adjust the solutions from the articles I found so it would fit my scenario.


What would be the best approach to accomplish this?

I hope that someone could help me out with this.

Thanks in advance for helping out!


Kind regards,


2 Replies

In the meanwhile I have found a usable PnP script for this. I will include it below for future reference and try it out. I have attached the example script.

Thanks Joost Van der Linden.
This saves me a lot of time to create one.