Get File Type Size and Count

Get File Type Size


Did you ever wanted to know the number of dll files in C:Windows ? How much megabytes it represent ? Maybe you have a C:Script folder and want to know the number of .ps1 files against the number of .vbs files ? Maybe you want some knowledge about the data stored on your files servers ? Maybe you want to know the different types of photo you own ?You can do it with PowerShell, just set the location of your prompt and use those lines :

Get-ChildItem -Recurse | Where-Object -FilterScript {$_.PSIsContainer -eq $false} | Group-Object -Property Extension | ForEach-Object -Process {
    New-Object -TypeName PSObject -Property @{
        'Extension'= $
        'Count' = $_.count
        'TotalSize (MB)'= '{0:N2}' -f ((($ | Measure-Object length -Sum).Sum) /1MB)
        'TotalSize (GB)'= '{0:N2}' -f ((($ | Measure-Object length -Sum).Sum) /1GB)
        'TotalSize'    = (($ | Measure-Object length -Sum).Sum)
} | Sort-Object -Descending -Property 'Totalsize'

Note : This code is v2 compatible.

What is does ? First, it grabs all the files and folders in directory you are in. Then, it exclude the directories, and group file by extension, and finally, for each extension, it measure the number of files, and the size of them. There is some maths for MB/GB display with some composite formatting.

Get File Type Size – Example :

For C:Windows, you may want to use “Out-GridView” for a readable output :

Get File Type Size - Example

Get File Type Size – Example

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.