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 : http://1drv.ms/1rX3iVF (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`:\”,”\\corp.intusurg.com\files\document-control-old\”) | Out-File -FilePath $FileList -Append
“`n`r`n`r” | Out-File -FilePath $filelist -Append
}