≡ Menu

count files by extension using powershell

Just a tip. This will help you to list files count by extension.

Get-Childitem c:\local -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc

Comments on this entry are closed.

  • Maria March 13, 2012, 8:18 am

    Awesome – saved my life

  • hamid April 25, 2012, 10:14 am

    hi
    that’s grate
    I need this code
    😉

  • Rob Andren March 6, 2013, 11:01 am

    Brilliant. Glad I didn’t spend any time reinventing the wheel. Exactly what I needed. Thank you.

  • lync August 8, 2014, 8:10 pm

    Thank you – saved my day !!!!

  • Jim October 20, 2014, 7:13 pm

    Just what I needed. Thanks.

  • Brian July 2, 2015, 11:00 pm

    If you’re using a newer version of PS, you can replace the where clause with -file.

    get-childitem c:\local -file |group Extension -NoElement |sort Count -desc

    Don’t know how much faster this is, but there is a performance improvement.

  • mumu July 12, 2018, 1:00 pm

    How to do output in percent (or better both)?
    I don’t have a mind how to do it in one string with only one pass.

  • Lucas September 18, 2018, 8:22 pm

    E para verifica o tamanho ocupado no disco por cada extensão?

    • Wintel Rocks October 8, 2018, 8:30 pm

      No provision available to check the space occupied by each extension type.

  • franz March 12, 2019, 12:31 am

    Awesome! thank you 🙂

  • Casey September 30, 2019, 3:16 pm

    Man… in 2019 this is still gold. If you are using the latest PS version try the following if yours is not working:

    Get-ChildItem C:\windows\system32 -Recurse | Where { -not $_.PSIsContainter } | group Extension | Select Count, Name | Sort Count -Descending

    Cheers!

  • Alicia White February 7, 2020, 8:54 pm

    That’s awesome! Just what I needed.

    I modified it a bit so it will prompt for the path (UNC paths work with this, which is what I need):

    $Path = Read-Host -Prompt ‘What is the directory or path?’
    Get-Childitem $Path -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc

  • RC April 5, 2020, 8:31 am

    is there a way to speed this up? My folders have in excess of 3-10M files each and this is taking forever.
    Help would be appreciated!!

  • Tommy August 28, 2021, 3:21 pm

    Unfortunately – it ain’t showing full result number in case of large amount of files. For instance i have folder with over 26milions files, and this script in result shows “….932”, instead of “26121932”

    • JonnyG October 25, 2021, 4:34 pm

      Tommy try this, it solved the issue for me.
      Get-ChildItem d:\users -Recurse | Where { -not $_.PSIsContainter } | group Extension | Select Name, Count | Sort Count -Descending