I have a client who was migrating from a file share to SharePoint Online. They have a very detailed business process that was reflected in a highly nested grouping of folders. (Think about a set of folders numbered 1 – 5 with each of those folders containing folders numbered 1 – 5 and then possibly each of those folders having folders.) We moved the shared drive files as-is to SharePoint Online. However, the volume of files being migrated meant the client was running out of storage space in their tenant. These files were inactive, serving as an archive of past project files. In an effort to cut down on wasted storage space, I wanted to write a PowerShell script that would iterate through a set of folders in a library, and then delete any folders which were empty, having no files or folders inside of them. To use the script, simply specify the site collection URL, the relative URL of the document library, and the name of the document library, and the script will do the rest. (Note that the script currently simply outputs the response to the console, but the script could be easily modified to output the results to a text file. Additionally, whereas parameters are hardcoded, it would be easy enough to make them input parameters if you wanted to automate the script.) The script utilizes the SharePoint Patterns and Practices PowerShell module.
You can find the script on GitHub.