在PowerShell中自动确认删除

问题描述 投票:28回答:6

我正在运行以下命令:

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”?

scripting powershell windows-vista automation
6个回答
22
投票

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


38
投票

默认为:无提示。

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

但是,当目标时它仍然会提示:

  • 是一个目录
  • 它不是空的
  • 并且未指定-Recurse参数。

-Force还需要删除隐藏和只读项目等。

把它们加起来:

Remove-Item -Recurse -Force -Confirm:$false

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


29
投票

添加-confirm:$ false以禁止确认。


9
投票

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

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


6
投票
Remove-Item .\foldertodelete -Force -Recurse

0
投票

你只需要在线后添加一个/A

例:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname} /a
© www.soinside.com 2019 - 2024. All rights reserved.