Powershell file query, sort, output

Have a very basic Powershell request, but my experience is even more basic. Please Humor me...
I need to Write a Windows PowerShell script that will perform the following functions:
1. Search the computer for files ending with a .doc, .docx, .xls, or .xlsx file extension.
2. Output the filenames and sizes (in groups by file extension) to a text file named “File_Summary.txt”.
3. The output should also conclude with a total of the number of files and total file size for each file extension.

Here is as far as I can get:
dir -recurse  -include *.docx, *.xlsx c: | select-object Length, name | sort-Object extension
Who is Participating?
SubsunConnect With a Mentor Commented:
$Search = "C:\"
$Outfile = "C:\Temp\report.csv"
$Files = Dir $Search -recurse  -include  *.doc,*.docx,*.xls,*.xlsx -EA SilentlyContinue | 
	select-object Length,name,Fullname,extension | sort-Object extension

$Files | Export-Csv $Outfile -NoTypeInformation

$Files | Group extension -NoElement | % {$Ext = $_.Name;$_ | Select @{N="Extension";E={$_.Name}},Count,`
		@{N="SizeMB";E={"{0:N2}" -f (($Files | ?{$_.extension -eq $Ext} | Measure Length -Sum).Sum /1MB)}}} | 
		ConvertTo-Csv -NoTypeInformation | Out-File $Outfile -Append -Encoding ASCII

Open in new window

sflbuzzmanAuthor Commented:
Thanks Subsun. Way more than I anticipated in the setup ... but, just goes to show how much that I have to learn.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.