Posted in Computers and Internet

PowerShell: Script to generate report by file type/extensions (number of files by extension)

I had a need to count number of files by it’s type. E.g., how many office files, PDF files, etc., I wrote an quick script to generate report on Number of Files by file type (extension) and list of files by file type. Go ahead use my script if you want. Script generates two CSV files on your current working directory.

.docx   150
.txt    138
.pdf    95
.doc    86
.JPG    60
.xls    43
.vsd    32
.xlsx   24
.msg    15
.html   11

Download the PowerShell Script : (or copy/paste the below script)

param ($path)

Script Name: Generate-Report-by-FileType.ps1
Purpose: Count the number of files by file extension for the given path. Write
the results in a CSV file on the current working folder.
Written By Anand, the Awesome, Venkatachalapathy
Date Written: Sep 10 2014

    Parameters: Path name (e.g., C:\users\awesome\, \\fileserver1\share1)

# file name to log file extension and number of files by the type
$filetypelist = “.\Directory report for ” + (Split-Path -Path $path -Leaf) + “.csv”

# file name to log file list by extension
$filelist = “.\File report for ” + (Split-Path -Path $path -Leaf) + “.csv”

#Search the given path and group the results by Extension
$DirInfo = Get-ChildItem -Path $path -Recurse | where { -not $_.PSIsContainer } | group Extension  | sort count -desc

#Write the results in to log files
“Extension Name`tFile Count” | Out-File -FilePath $filetypelist
foreach($f in $DirInfo)
$f.Name + “`t” + $f.Count
$f.Name + “`t” + $f.Count | Out-File -FilePath $filetypelist -Append

“File Report on Extension`: ” + $($f.Name) + ” (Count`: ” + $f.Count + “)” | Out-File -FilePath $FileList -Append
($f.Group.FullName).Replace(“e`:\”,”\\\files\document-control-old\”) | Out-File -FilePath $FileList -Append
“`n`r`n`r” | Out-File -FilePath $filelist -Append


Being in Silicon Valley for years, I became a IT Infrastructure Geek by experience and surrounded by other Geeks everywhere. I try to help others by the solutions I found on odd occasions.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s