在PowerShell中自动确认删除

时间:2011-01-20 23:08:12

标签: scripting powershell windows-vista automation

我正在运行以下命令:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname}

这经常提示我这样:

Confirm
The item at C:\temp\f\a\d has children and the Recurse parameter was not specified. If you continue,
all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): 

如何将其自动设置为" A"?

6 个答案:

答案 0 :(得分:34)

默认为:无提示。

您可以使用-confirm禁用启用它-confirm:$false

然而,当目标:

时,它仍然会提示
  • 是目录
  • 它不是空的
  • 未指定-recurse参数。

总结一下:

Remove-Item -recurse -force -confirm:$false

......应涵盖所有情景。

答案 1 :(得分:27)

添加 -confirm:$ false 以取消确认。

答案 2 :(得分:21)

尝试使用-Force上的Remove-Item参数。

答案 3 :(得分:8)

在remove-item之后添加-recurse,-force参数也有助于删除隐藏文件 e.g:

gci C:\ temp \ -exclude * .svn-base,“。svn”-recurse | %{ri $ _ -force -recurse}

答案 4 :(得分:5)

Remove-Item .\foldertodelete -Force -Recurse

答案 5 :(得分:0)

您只需要在该行后面添加/A

示例:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname} /a
相关问题