Automatic confirmation of deletion in powershell

2019-03-17 08:00发布

I'm running the following command:

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

Which prompts me very frequently like this:

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"): 

How can I have it automatically set to "A"?

6条回答
对你真心纯属浪费
2楼-- · 2019-03-17 08:11

Add -recurse after the remove-item, also the -force parameter helps remove hidden files e.g.:

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

查看更多
做自己的国王
3楼-- · 2019-03-17 08:20

Add -confirm:$false to suppress confirmation.

查看更多
戒情不戒烟
4楼-- · 2019-03-17 08:23

The default is: no prompt.

You can enable it with -confirm or disable it with -confirm:$false

However, it will still prompt, when the target:

  • is a directory
  • and it is not empty
  • and the -recurse parameter is not specified.

To sum it up:

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

...should cover all scenarios.

查看更多
Bombasti
5楼-- · 2019-03-17 08:28

You just need to add a /A behind the line.

Example:

get-childitem C:\temp\ -exclude *.svn-base,".svn" -recurse | foreach ($_) {remove-item $_.fullname} /a
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-03-17 08:30
Remove-Item .\foldertodelete -Force -Recurse
查看更多
等我变得足够好
7楼-- · 2019-03-17 08:37

Try using the -Force parameter on Remove-Item.

查看更多
登录 后发表回答