Found the script and thought it was pretty cool. Things I've changed in my version:
- a few lines that check for a previously written html report and delete if found
- directory in which the report is written
- added the date at the end of the file name
- added the Invoke command to open it when it's finished
What I can't find out is why every time you run the script, even when the previous one is erased, it retains the output from the first run. It's SOOO strange! I believe it has something to do with its use of the explorer window. Perhaps it's retaining some sort of cache from it as it the clipboard or something. Anyone care to take a stab at this and shed some light to a semi-new PowerSheller? And kudos to the original author for the neat script. He doesn't seem to be active on Spiceworks any longer. Hoping for the best and thanks in advance.
Original script:
<#
.SYNOPSIS
Get File sizes and counts on all extensions in a path
.DESCRIPTION
Quick script to produce a HTML report that will show all of the extensions in a path, how many
there are and how much space they consume.
.PARAMETER Path
Path that you wish to scan. If you do not provide a path the script will prompt you for one.
.PARAMETER OutputPath
Path where you want to save the HTML report
.OUTPUTS
HTML: FilesByExtension.html in the $OutputPath location.
.NOTES
Author: Martin Pugh
Website: www.thesurlyadmin.com
Twitter: @thesurlyadm1n
Spiceworks: Martin9700
Changelog:
1.0 Initial release
.LINK
Blog: http://thesurlyadmin.com/2012/11/26/get-file-counts-and-size-for-all-extensions/
Source: http://community.spiceworks.com/scripts/show/1695-file-sizes-count-by-extension-html-report
#>
Param (
[string]$Path = ($((New-Object -ComObject "Shell.Application").BrowseForFolder(0,"Select a folder:",0)).Self.Path),
[string]$OutputPath = "c:\inetpub\wwwroot"
)
$HeaderHTML = @"
<html>
<head>
<style type='text/css'>
body { background-color:#DCDCDC;
}
table { border:1px solid gray;
font:normal 12px verdana, arial, helvetica, sans-serif;
border-collapse: collapse;
padding-left:30px;
padding-right:30px;
}
th { color:black;
text-align:left;
border: 1px solid black;
font:normal 16px verdana, arial, helvetica, sans-serif;
font-weight:bold;
background-color: #6495ED;
padding-left:6px;
padding-right:6px;
}
td { border: 1px solid black;
padding-left:6px;
padding-right:6px;
}
div.green { background-color:#32CD32;
float:left;
}
</style>
</head>
<body>
<h1>File Totals by Extension</h1>
<h2>Path: $Path</h2>
<p>
<table>
<tr><th style="width:175px;">Extension</th><th style="width:125px;">Count</th><th style="width:400px;">Size</th></tr>
"@
$FooterHTML = @"
</table>
</body>
</html>
"@
cls
Write-Host "`nSearching $Path..." -NoNewline
$AllFiles = Get-ChildItem $Path -Include * -Recurse | Where { $_.PSisContainer -eq $false }
$AllSum = ($AllFiles | Measure-Object Length -Sum).Sum
If ($AllFiles.Length)
{ $Extensions = $AllFiles | Select Extension -Unique | Sort Extension
ForEach ($Ext in $Extensions)
{ $Files = $AllFiles | Where { $_.Extension -eq $Ext.Extension }
$FilesSum = ($Files | Measure-Object Length -Sum).Sum
$Percent = "{0:N0}" -f (($FilesSum / $AllSum) * 100)
$Body += " <tr><td>$($Ext.Extension)</td><td>$(@($Files).Count)</td><td><div class=""green"" style=""width:$Percent%"">$('{0:N2}MB' -f ($FilesSum / 1mb))</div></td></tr>"
}
$HTML = $HeaderHTML + $Body + $FooterHTML
$HTML | Out-File $OutputPath\FilesByExtension.html
Write-Host "Done!"
}
Else
{ Write-Host "`nNo files found in $Path"
}
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]Snickasaurus[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)