I had recently posted here regarding my task to move Document Libraries across sites. Since then I started learning Powershell and I am getting the grip, albeit in a slow manner. I have managed to create a list, add fields to it, and move the data across sites. The sites are within the same Office 365 but are different site collections.
Now to describe my actual task and therefore my aim; I have a document library, whose hierarchy looks something like this:
- Document Library - Scanned Docs (1)
- Document Sets - Representing Clients (1000)
- Documents - Representing Invoices (100,000)
i.e. 1 Document Library, around 100 document sets, and around 100,000 documents. This means that each Document set contains an average of 100 documents, which represent invoices.
Having managed to fiddle with lists, I am now trying to do the same but with Document Sets. If I could somehow get into the document library and traverse the whole list of document sets, and then go inside each document set and handle each document, that would be awesome.
My issue is this, with lists, I created a context using the root URL of the Sharepoint site where the list resides, and the follow line of code gets the list by its name:
However, there is no equivalent for Document Sets.
What I found is this:
It takes 'context' and 'folder' as parameters. I have no clue what to put in the Folder place. Should the context be created on the root folder's url and let the document library represent the 'folder'? I don't think this would make sense as a Document Library is more like a list than a 'folder'.
I also found this (c# code):
I tried to transform the code into Powershell:
$ListItem = Microsoft.Sharepoint.Client.DocumentSet.GetDocumentSet(...); // DocumentSet item $Context.Load($ListItem); $Context.ExecuteQuery(); $documentSet = Microsoft.Sharepoint.Client.DocumentSet.GetDocumentSet($Context, $ListItem.Folder); $Context.Load($documentSet); $Context.ExecuteQuery();
Well am I on the right track? What goes instead of the '...'?
Question 2: After being able to retrieve a document set I would need to somehow manage to traverse the document library and get the document sets one by one. Furthermore, I would need to go into each document set and get the documents one by one.
How do I do this? It seems practically an impossible task to find examples and therefore any help will be greatly appreciated. All I need is a kick start and I will take it from there.