13 July 2016 - v1.3
  Added MaxFileSize parameter, updated Log function
11/03/2014 - v1.2
    Added 'Report run time' at the bottom
    Fixed bug when no files are found that match criteria
    Turned into function
    Bundled with EnhancvedHTML2
    Added SizeUnit parameter

Screen output will look like:

The HTML report will look like:


7/20/2014: V1.1 - updated log function, some cosmetic changes


A question was posted a few days ago on the Powershell.org Q&A forum:

I'm trying to get people to clean up old files. Never an easy job. To help them out, I want to generate reports of their department folders. One report would list their Powerpoint files, another PDFs and a third, zip files.

Many of us have been in this situation where data sprawl goes a bit out of control. This script helps produce HTML reports that can be customized to report on:

For more information see http://superwidgets.wordpress.com/category/powershell/


To use this script, download it, run it to load it. To see help type in:

PowerShell
Edit|Remove
help Report-onFiles -full
 You'll see output like:
NAME
    Report-OnFiles
    
SYNOPSIS
    Script to get list of certain files by extension, and compile HTML reports
    
SYNTAX
    Report-OnFiles [-TargetFolders]  [[-FileTypes] ] [[-Properties] ] [[-MinFileSize] ] [[-SizeUnit] ] [[-HTMLFile] ] [[-LogFile] 
    ] [-WhatIf] [-Confirm] []
    
DESCRIPTION
    Script to get list of certain files by extension, and compile HTML reports
    CSS Style and EnhancedHTML2 functions courtesy of Don Jones - Powershell.org

PARAMETERS
    -TargetFolders 
        List of folders to search and report on. 
        Can use local paths or UNC paths.
        Example: "c:\", "\\server\share\folder"
        
        Required?                    true
        Position?                    1
        Default value                
        Accept pipeline input?       true (ByValue, ByPropertyName)
        Accept wildcard characters?  false
        
    -FileTypes 
        List of file extensions to search and report on. 
        Wildcards can be used.
        Example: "zip", "doc?", "cs*"
        
        Required?                    false
        Position?                    2
        Default value                *
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -Properties 
        List of file properties to show in the report.
        Default: "Name","DirectoryName","Extension","Length","CreationTime","LastAccessTime","LastWriteTime","Attributes"
        This parameter cannot accept other properties than those listed.
        
        Required?                    false
        Position?                    3
        Default value                @("Name","DirectoryName","Extension","Length","CreationTime","LastAccessTime","LastWriteTime","Attributes")
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -MinFileSize 
        Minimum file size in bytes to include in the report.
        Default is 0 bytes which includes all files.
        Example: 1MB => this will report on files that are 1MB or larger only
        
        Required?                    false
        Position?                    4
        Default value                0
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -SizeUnit 
        The file length unit - options are: "Byte","KB","MB","GB","TB"
        Default is "Byte"
        
        Required?                    false
        Position?                    5
        Default value                Byte
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -HTMLFile 
        Path to the output HTML file
        If absent, it will default to a file similar to .\Report-OnFiles_20141103_061915AM.html
        
        Required?                    false
        Position?                    6
        Default value                ".\$($myinvocation.mycommand.Name.Split(".")[0])_$(Get-Date -format yyyyMMdd_hhmmsstt).html"
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -LogFile 
        Path to the file where script steps are logged
        If absent, it will default to a file similar to .\Report-OnFiles_20141103_061915AM.txt
        
        Required?                    false
        Position?                    7
        Default value                ".\$($myinvocation.mycommand.Name.Split(".")[0])_$(Get-Date -format yyyyMMdd_hhmmsstt).txt"
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -WhatIf []
        
        Required?                    false
        Position?                    named
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    -Confirm []
        
        Required?                    false
        Position?                    named
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false
        
    
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see 
        about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 
    
NOTES
    
        Script by Sam Boutros 
        07/15/2014 - V1.0
        07/20/2014 - V1.1 - updated Log function, cosmetic changes
        11/03/2014 - v1.2
          Added 'Report run time' at the bottom
          Fixed bug when no files are found that match criteria
          Turned into function
          Bundled with EnhancvedHTML2
          Added SizeUnit parameter
    
    -------------------------- EXAMPLE 1 --------------------------
    
    C:\PS>Report-onFiles -TargetFolders C:\Sandbox
    
    This example reports on all files under c:\sandbox folder
    
    -------------------------- EXAMPLE 2 --------------------------
    
    C:\PS>Report-onFiles "C:\Sandbox" , "\\Server5\Scripts\"
    
    This example reports on all files under C:\Sandbox & \\Server5\Scripts\ folders
    
    -------------------------- EXAMPLE 3 --------------------------
    
    C:\PS>Report-onFiles -TargetFolders "C:\Sandbox" -FileTypes txt,cs*
    
    This example reports on all files under C:\Sandbox with txt or cs* extensions
    
    -------------------------- EXAMPLE 4 --------------------------
    
    C:\PS>Report-onFiles -TargetFolders "C:\Sandbox" -FileTypes txt,cs* -Properties "Name","DirectoryName","Extension","Length","LastAccessTime"
    
    This example reports on all files 
      under C:\Sandbox 
      with txt or cs* extensions
      showing only the "Name","DirectoryName","Extension","Length","LastAccessTime" file properties

    -------------------------- EXAMPLE 5 --------------------------
    
    C:\PS>Report-onFiles -TargetFolders "C:\Sandbox" -FileTypes txt,cs* -Properties "Name","DirectoryName","Extension","Length","LastAccessTime" -MinFileSize 1KB
    
    This example reports on all files 
      under C:\Sandbox 
      with txt or cs* extensions
      and larger than 1KB in size (length)
      showing only the "Name","DirectoryName","Extension","Length","LastAccessTime" file properties
    
    -------------------------- EXAMPLE 6 --------------------------
    
    C:\PS>Report-onFiles -TargetFolders C:\Sandbox,\\Server5\Scripts\ -FileTypes ps?,cs* -MinFileSize 1KB -SizeUnit KB
    
    This example reports on all files 
      under C:\Sandbox and \\Server5\Scripts\
      with txt or cs* extensions
      and larger than 1KB in size (length)
      listing file size (length) in KB
    
RELATED LINKS
    https://superwidgets.wordpress.com/category/powershell/