How to Find Empty Folders with or without PowerShell

{{ firstError }}
We care about security of your data. Privacy Policy
Native Auditing Netwrix Auditor for Windows File Servers
Native Auditing
Netwrix Auditor for Windows File Servers
  1. 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 '\\pdc\Shared' -Recurse | Where { $_.PsIsContainer -eq $true }

$share | Where { $_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0 }

  1. Review the results.
Command_Empty Folders
  1. Run Netwrix Auditor → Navigate to “Reports” → Expand the “File Servers” section → Go to “File Servers – State-in-Time” → Select “Empty Folders” → Click “View”.
  2. To export the report to CSV or another format, click the “Export” button → Choose a format from the dropdown menu → Click "Save".
Empty Folders Netwrix Auditor Report

Easily Find Empty Directories on Your File Server

Over time, file shares tend to collect empty folders, which makes it harder for users to find the data they need. Therefore, from time to time, IT pros need to find empty folders so they can remove the empty directories. With manual methods, searching for empty folders takes a lot of time, so you might want to automate this task with a Windows PowerShell script like the one provided above; it parses all folders on a share and lists those that contain no files or other folders. However, this script can take a long time to execute if there are many folders on your file server.

It is much easier and quicker to open a predefined report. Try Netwrix Auditor for Windows File Servers. In a few clicks, you can get a clear list of all empty folders, so you can review and delete empty folders for a share that’s easier to use and manage. NA even helps you further optimize your file share structure by reporting on duplicate files and folders and stale data.

Of course, Netwrix Auditor software does a lot more than report on empty folders and stale data. For example, it reports on changes made to files, folders, shares and permissions; delivers visibility into effective permissions; and alerts you about critical events, such as the modification of large number of files in a short period of time, which can be a sign of a ransomware attack in progress. No matter what you want to report on, you’ll save time with its predefined and custom reports, flexible filtering, exporting options and report subscriptions.

Related How-tos