Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic confirmation of deletion in powershell

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

like image 911
siliconpi Avatar asked Jan 20 '11 23:01

siliconpi


People also ask

How do I Auto confirm in PowerShell?

You have to use the -Confirm switch to the command to prompt the user for confirmation. It forces the command to display the confirmation prompt in PowerShell. A simpler way to use the -Confirm switch would be by using it in the Remove-Item cmdlet, which can produce a confirmation action in simpler command.

How do I turn off confirmation in PowerShell?

If the script uses Powershell cmdlets, you can specify -Confirm:$false to suppress the prompt.

What does recurse do in PowerShell?

Summary of PowerShell -Recurse -Recurse is a classic switch, which instructs PowerShell commands such as Get-ChildItem to repeat in sub directories. Once you remember that -Recurse comes directly after the directory, then it will serve you well in scripts that need to drill down to find information.


2 Answers

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.

-Force is required to also remove hidden and read-only items etc.

To sum it up:

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

...should cover all scenarios.

like image 144
marsze Avatar answered Oct 11 '22 12:10

marsze


Add -confirm:$false to suppress confirmation.

like image 32
mjolinor Avatar answered Oct 11 '22 13:10

mjolinor