Tracking empty folders on Windows File Servers is a vital part of IT operations. One example of why you would want to do this is if you’re going to permanently archive a folder. Before archiving it’s a good idea to clean up and remove the excess baggage of any folders that no longer contain anything. Cleaning up and removing unnecessary empty folders also makes it more efficient for users to find the data they need. Therefore, from time to time, it will be necessary to locate all empty folders so that they can be removed.
Using manual methods, searching for empty folders could take a lot of time and effort, so an alternative is to automate this with a Windows PowerShell script, an example of which is given below. It parses all folders on a share and lists those that contain no files or other folders.
In this article, we will look at how to find empty folders using the native PowerShell method.
Using PowerShell to Find Empty Folders in File Server
Open the Microsoft PowerShell ISE
Using an admin account that has full access to your file share, run the following script on the workstation, specifying the network path of the shared drive:
$share = Get-ChildItem '\\ServerName(IP)\Folder' -Recurse | Where { $_.PsIsContainer -eq $true }
$share | Where { $_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0 }
Below is the output
The Lepide File Server Auditing Solution
Lepide Auditor for File Server enables you to audit files and folders providing visibility over when they are created, accessed, modified, moved, renamed, copied, or deleted. The Lepide’s File Server Auditing Software can also help organizations track and compare permissions across their file servers. Our file server auditing software addresses the challenges of the insider-threat and the data reporting requirements associated with common regulatory compliance mandates.
There are many pre-defined reports included with Lepide Auditor for File Server for file server auditing. One of these is the File and Folder Deleted report and an example is shown below: