How to get the list of empty folders using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To get the list of empty folder on the windows OS using PowerShell, we can use the below method.

gci C:\Temp -Recurse | foreach {
   if( $_.psiscontainer -eq $true){
      if((gci $_.FullName) -eq $null){$_.FullName}
   }
}

The above command checks the C:\Temp folder and its subfolders and if the content is empty it returns the Folder full path. The PSISContainer property stands for the folder and GCI is the alias of the Get-ChildItem command. We can alternatively use the below command, instead of using the PSISContainer property.

gci C:\Temp -Recurse -Directory | foreach {
   if((gci $_.FullName) -eq $null){$_.FullName}
}
raja
Published on 30-Mar-2021 13:08:29
Advertisements