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
1
u/SkullyRed Jan 12 '26
Nope
\{0:N2}\ : The term '\{0:N2}\' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Users\mike\Desktop\PowerShell\MP3 Under 5MB.ps1:2 char:47
+ $Files | ForEach-Object { "$($_.FullName) - $(\'{0:N2}\' -f ($_.Lengt ...
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\{0:N2}\:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException