I simply want to delete empty folders in a path along with folders that only have .txt files. I have this, but it doesn't work.
$tdc = "C:\My Shared Folder"
while (
$empties = Get-ChildItem $tdc -Recurse -Directory | Where {
(GCI -Path $_.FullName -File -Exclude ("*.txt") | Measure-Object).Count -eq 0 -and
$_.GetDirectories().Count -eq 0
}
) {
$empties | Remove-Item -Force -Verbose
}