≡ Menu

List the files greater than given size using powershell

Below powershell code helps you to list the files which are greater than given size(2GB in this case) and output the file sizes in MB/GB format. This command searches for files inside c:\mydata folder. You can run this against any folder.

Get-ChildItem -path c:\mydata -recurse | Where-Object  {
    ($_.Length /1GB) -gt 2 
} | ForEach-Object {
Happy Learning,
Sitaram Pamarthi


Comments on this entry are closed.

  • Muhammad Usman Janjua May 22, 2011, 11:15 am

    A small correction needed in the command above. The switch should be “-recurse” instead of “-recursive”. Thanks.

  • Sitaram Pamarthi May 23, 2011, 4:45 pm

    Thanks for pointing the typo. I made the correction.

  • Martin February 17, 2016, 12:48 pm

    Better solution: fileas larger than 50 MB on drive C:
    Get-ChildItem -Path C:\ -Recurse | Where-Object {$_.length/1MB -gt 50} | select fullname,@{n=”Size MB”;e={$_.length/1MB}}
    Output of this command is still object, so you cane pipe it for instance to remove-item and so on.

  • Abigail Ava January 21, 2017, 2:38 pm

    Sometimes we get an error when we try to delete a File or a folder for no reason , but of course there is a reason.We have many damage file or blocked files.Do not worry if we want to remove the error files or too long path files from our system,here I suggest a smooth way.So use “Long path tool” software and keep yourself.

  • Paramveer S Arora February 23, 2018, 5:05 pm

    What if we have to do it on 10 servers remotely can it take a server.txt as input and write for all the OS.

    • Wintel Rocks February 27, 2018, 11:22 pm

      Hi, You can execute this code through PowerShell Remoting.

  • Brandon White March 25, 2019, 11:37 pm

    Is there also a way to make this export to a /txt or .csv file as well as display it on screen?

  • Ahmad June 20, 2019, 5:14 pm

    It worked ! thanks a lot for sharing