Mahmoud ElMansy: knowledge meant to be free

PowerShell get list of all files by size or name

I having fun Playing with Windows PowerShell
This Post will demonstrate how cool it’s and this will be the beginning of new seriaes talking about PowerShell.
let’s go ahead if you has folder contains files and you want to get a list of all files in this folder and
sub folder by size?! this is a very logical question and the answer is use Power shell
just write this code

get-childitem * -recurse |where-object { $_.Length -eq 0 }
--or you can export it to csv
get-childitem * -recurse |where-object { $_.Length -gt 20} | export-csv newfile.csv

we can also change condition
-lt — Less than
-le — Less than or equal to
-gt — Greater than
-ge — Greater than or equal to
-eq — Equal to
-ne — Not equal to
-like – Like; uses wildcard for pattern matching

We can also search by name .

-- to search in the current location and sub folders
get-childitem * -recurse | Where-Object {$ -like "*test*"}
-- to search in the specified location
Get-ChildItem c:\scripts | Where-Object {$ -like "*test*"}
-- to search in the specified location and sub folders
Get-ChildItem c:\scripts -recurse | Where-Object {$ -like "*test*"}