- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get empty files in Windows OS using PowerShell?
To get the list of empty files in Windows OS using PowerShell, there are two ways,
a) Using Length parameter. We will count the length of the file. If it is 0 then the file is empty as shown below.
Get-ChildItem C:\Temp\ -Recurse | where{$_.Length -eq 0} | Select @{N='EmptyFiles';E={$_.FullName}}
Output:
b) Another method is a long one that we don’t want to go into. We need to check each file's content and if it is empty then we will declare that file as an empty file.
Get-ChildItem C:\Temp -Recurse -File | foreach{ if((Get-Content $_.FullName) -eq $null){ $_.FullName }
This method is quite slow because it scans the entire content of each file. It is always better to use the first method.
- Related Articles
- How to delete empty files and folders using PowerShell?
- How to Get Windows features using PowerShell?
- How to enable or disable local user on Windows OS using PowerShell?
- How to get installed windows update using PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- How to get windows firewall profile settings using PowerShell?
- How to get the Windows certificate details using PowerShell?
- How to get the windows performance counter using PowerShell?
- How to get the windows authentication settings using PowerShell?
- How to get hidden files and folders using PowerShell?
- How to get the system files using the Get-ChildItem in PowerShell?
- How to get the list of empty folders using PowerShell?
- How to get the Azure storage container blobs (Files) using PowerShell?
- How to remove windows features using PowerShell?
- How to get only files but not the folders with Get-ChildItem using PowerShell?

Advertisements