r/PowerShell • u/SkullyRed • Jan 12 '26
Google solutions
Google search: find all files under 5mb mp3
This is what a Google search produced as a powershell command/script:
$( $Files = Get-ChildItem -Path "\\PC\Users\name\Music" -Recurse -Filter *.mp3 | Where-Object {$_.Length -lt 5MB} | Sort-Object Length) $Files | ForEach-Object { "$($_.FullName) - $(\'{0:N2}\' -f ($_.Length/1Kb))Kb" } >>C:\tmp\output.txt
The result:
At C:\Users\mike\Desktop\PowerShell\MP3 Under 5MB.ps1:1 char:143
+ ... Where-Object {$_.Length -lt 5MB} | Sort-Object Length) $Files | ForEa ...
+ ~~~~~~
Unexpected token '$Files' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
My powershell prowess score from 1-10 is (.05+/-).
I Ctrl-C, Ctrl-V, modify, save, run. In other words, I'm no programmer or powershell expert.
Why does this not work?
View all comments
Show parent comment
2
u/SVD_NL Jan 12 '26
In that case i'd replace the second command with:
$Files | Select-Object Name, Length, Directory | Export-Csv -Path .\output.csvYou can also use FullName instead of Name and Directory, depending on your needs.
Length is file size in bytes, you can open the csv in excel (or notepad, but excel is nicer for filtering and sorting)