在我的命令中使用ErrorAction Silentlcontinue后出错

时间:2017-04-07 06:15:21

标签: powershell

使用-Erroraction Silentcontinue后我仍然出错。这是我正在使用的命令:

 get-childitem c:\ -include *.bak -recurse | foreach ($_) {remove-item $_.fullname } -ErrorAction SilentlyContinue -ErrorVariable a

1 个答案:

答案 0 :(得分:4)

您可能在Get-ChildItem cmdlet中检索错误。所以你也应该在那里添加参数(-ea 0-ErrorAction SilentlyContinue的别名)。

由于Foreach-Object cmdlet采用管道对象,因此代码中Remove-Item cmdlet的使用已过时:

Get-ChildItem c:\ -include *.bak -recurse -ea 0 |  Remove-Item -ea 0