PowerShell出现批量删除脚本问题

PowerShell出现批量删除脚本问题,powershell,powershell-4.0,Powershell,Powershell 4.0,我正在尝试删除文件大小小于2kB的所有内容,并使用以下代码: Get-ChildItem $path -Filter *.html -Recurse -File | ? {$_.Length -lt 2000} | % {Remove-Item $_.FullName} 我经常遇到这样的错误: Remove-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard c

我正在尝试删除文件大小小于2kB的所有内容,并使用以下代码:

Get-ChildItem $path -Filter *.html -Recurse -File |
    ? {$_.Length -lt 2000} |
    % {Remove-Item $_.FullName}
我经常遇到这样的错误:

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 移除项:无法检索cmdlet的动态参数。 指定的通配符模式无效:07 somefilename filename.mp3 第1行字符:66 + ... -递归文件|?{$\.Length-lt 2000}|%{删除项$\.FullName} + ~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidArgument:(:)[Remove Item],参数BindingException +FullyQualifiedErrorId:GetDynamicParametersException,Microsoft.PowerShell.Commands.RemoveItemCommand
这可能会避免文件名中的[]通配符问题,通过管道将fileinfo对象直接删除该项

ls $path *.html -r -file | where length -lt 2000 | remove-item -whatif

路径或全名是否包含方括号[]?这些是通配符。请尝试
Remove Item-LiteralPath$\FullName