When you are required to check a folder if it is really empty or not with Powershell, this tutorial can help you a lot.

Check if a Folder is Empty in PowerShell

Open PowerShell with administrative privileges and execute the following script.

if( (Get-ChildItem C:\temp | Measure-Object).Count -eq 0)
{
 echo "Folder is empty"
} else { echo "Folder is not empty" }
How to Check if a Folder is Empty in PowerShell
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

3 thoughts on “How to Check if a Folder is Empty in PowerShell

  • Avatar
    October 15, 2019 at 6:43 pm
    Permalink

    $notEmpty = Test-Path -Path C:TinyTake*
    if ($notEmpty){
    Write-Host -f red “Path is not Empty”
    } else {
    Write-Host -f green “Path is empty”
    }

    Reply
    • Avatar
      October 15, 2019 at 8:42 pm
      Permalink

      or you can do shorter version

      if (Test-Path -Path C:temp*){
      Write-Host -f red “Path is not Empty”
      } else {
      Write-Host -f green “Path is empty”
      }

      Reply
  • Avatar
    July 20, 2020 at 6:54 am
    Permalink

    Thanks!
    For the record, my understanding is that test-path only checks to see whether the folder EXISTS, but Get-ChildItem will confirm whether the folder is empty

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*