I pieced the following together to "scan" a folder structure and output line-terminated paths of folders that contain no files, directly or indirectly. The script expects an argument of the top-level or root folder to check. It took a few minutes to run with a network share as target (contains 1,982 folders and 13,970 files). If you have tips for optimizing or a more elegant / different approach to suggest, I'm interested!
param([string]$PathRoot="");
[System.Collections.ArrayList]$emptyDirs=Get-ChildItem$PathRoot-Recurse|Where-Object {$_.PSIsContainer};
$emptyDirs.Insert(0, (Get-Item$PathRoot));
$dirsWithFiles=Get-ChildItem$PathRoot-Recurse|Where-Object {$_.PSIsContainer -and$_.GetFiles().Count}
for ($i=0; $i-lt$dirsWithFiles.length; $i++) {
for ($j=0; $j-lt$emptyDirs.Count; $j++) {
if ($dirsWithFiles[$i].FullName -like ("{0}*"-f$emptyDirs[$j].FullName)){
$emptyDirs.RemoveAt($j);
$j--;
}
}
}
$emptyDirs|ForEach-Object {$_.FullName};