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"?
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.
If the script uses Powershell cmdlets, you can specify -Confirm:$false to suppress the prompt.
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.
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:
-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.
Add -confirm:$false to suppress confirmation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With