Skip to content

Instantly share code, notes, and snippets.

@dbrack
Last active August 23, 2017 06:15
Show Gist options
  • Save dbrack/8afef731db86f1de06e7 to your computer and use it in GitHub Desktop.
Save dbrack/8afef731db86f1de06e7 to your computer and use it in GitHub Desktop.
Power shell script to find empty folders in a given path.
# to run this script, execute .\EmptyFolders.ps1 -path "path\to\search" -output "path\to\outputfile.txt"
# if output is not supplied, the file is created in the current working directory
#
# to run unsigned powershell scripts that were created on your local computer, run the following command in PowerShell (Run as administrator)
# set-executionpolicy remotesigned
#
# to completly disable signture checks, run
# set-executionpolicy unrestricted
param (
[string]$path = "",
[string]$output = "$pwd\output.txt"
)
write-output "Checking $path for empty folders..."
$out = (Get-ChildItem $path -recurse | Where-Object {$_.PSIsContainer -eq $True}) | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName
$out >> $output
write-output "wrote output to $output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment