I have an existing system that we are cleaning up with thousands of document libraries and moving the contents into Azure instead. I'm looking for a programmatic way to iterate over the lists to find ones that are empty and delete them. Does anyone have any samples (preferably using CSOM or powershell) to accomplish this that they would be willing to share?
At this point, I've come up with the following code to accomplish the task, however I'm getting the error "the underlying connection was closed: an unexpected error occurred on a receive" trying to load the lists due to a timeout because I have so many lists. Here's my solution so far hiding the user secrets of uid, pws, site.
var cred = new SharePointOnlineCredentials(uid, pws);
var context = new ClientContext(site);
context.Credentials = cred;
context.RequestTimeout = Timeout.Infinite;
var lists = context.Web.Lists;
context.Load(lists);
context.ExecuteQuery();
foreach(var list in lists)
{
list.DeleteObject();
list.Update();
}