Count files by extension in a given directory by PowerShell

Very often I just want to know how many files with a specific extension are available in a SharePoint project.The following blogpost supported this goal.

Retrieves the amount of file based on a specific filter.

The Get-FileCountByFilter.ps1 script crawls a given directory and uses a user definied filter to count the files.

Specifies the path to the root directory to start searching and counting.

Specifies the filter that is used to count only the files that apply to this filter.

None. You cannot pipe objects to Get-FileCountByFilter.ps1.

Sytem.Int32. Get-FileCountByFilter returns the number of results found.

C:\PS> .\Get-FileCountByFilter.ps1 -StartDirectory c:\source\projects\

param (
	[Parameter(position=0, Mandatory=$true, ValueFromPipeline=$false, HelpMessage="Provide directory where all the result files are located.")]
Get-ChildItem $StartDirectory -Recurse | ? {-not $_.PSIsContainer} | group Extension -NoElement | sort count -desc



VN:F [1.9.22_1171]
Rating: 10.0/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)
Count files by extension in a given directory by PowerShell, 10.0 out of 10 based on 4 ratings