1

I'm trying to delete everything with less than 2kB file size and am using the following code:

Get-ChildItem $path -Filter *.html -Recurse -File |
    ? {$_.Length -lt 2000} |
    % {Remove-Item $_.FullName}

I keep getting errors like this:

Remove-Item : Cannot retrieve the dynamic parameters for the cmdlet.
The specified wildcard character pattern is not valid: 07 somefilename
filename.mp3
At line:1 char:66
+ ... -Recurse -File | ? {$_.Length -lt 2000} | % {Remove-Item $_.FullName}
+                                                  ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-Item], ParameterBindingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.RemoveItemCommand
2
  • Does the path or fullname have square brackets [ ] in it? Those are wildcards. Commented Jul 16, 2019 at 14:08
  • 1
    Try Remove-Item -LiteralPath $_.FullName Commented Jul 16, 2019 at 14:12

1 Answer 1

1

This would probably avoid the [ ] wildcard in filename problem, piping the fileinfo object directly to remove-item.

ls $path *.html -r -file | where length -lt 2000 | remove-item -whatif
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.