param ( [string]$Path = $(Read-Host "Scan path") ) if (!(Test-Path $Path)) { Write-Host "Error: Path not exist" -ForegroundColor Red exit } $EmptyFolders = Get-ChildItem -Path $Path -Recurse -Directory | Where-Object { @(Get-ChildItem -Path $_.FullName).Count -eq 0 } if ($EmptyFolders.Count -eq 0) { Write-Host "no empty folders found" -ForegroundColor Green } else { foreach ($folder in $EmptyFolders) { Write-Host "Deleted: $($folder.FullName)" -ForegroundColor Yellow Remove-Item -Force -Recurse $folder.FullName } Write-Host "All empty folders deleted" -ForegroundColor Green }