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" }
$notEmpty = Test-Path -Path C:TinyTake*
if ($notEmpty){
Write-Host -f red “Path is not Empty”
} else {
Write-Host -f green “Path is empty”
}
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”
}
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