Automatic confirmation of deletion in powershell
116,542
Solution 1
Try using the -Force
parameter on Remove-Item
.
Solution 2
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.
Solution 3
Add -confirm:$false to suppress confirmation.
Solution 4
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}
Solution 5
Remove-Item .\foldertodelete -Force -Recurse
Author by
siliconpi
Updated on July 09, 2022Comments
-
siliconpi almost 2 years
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"?
-
JasonMArcher over 13 yearsThis WILL NOT work. -Confirm is for forcing confirmation. Having it off just runs the normal decision logic.
-
Kiquenet about 11 yearsdo you use -force -confirm:$false ?
-
Jürgen Steinblock almost 7 years
-recurse
prevents confirmation for removing non empty folders. Thanks. -
Shayan Zafar about 3 yearsplease see below answers for a more comprehensive answer to this problem.