As TheMadTechnician points out, it is the -Recurse switch that is needed to suppress the extra confirmation prompt that is presented when Remove-Item is called to remove a nonempty container (directory).
This extra confirmation prompt is specifically presented for the higher-risk operation of removing containers along with their children and is independent of the common confirmation mechanism:
- That is, neither the cmdlet's declared impact level, nor the presence of
-Confirm or -Confirm:$False, nor the value of the $ConfirmPreference preference variable impact whether the extra prompt is shown.
- These elements do, however, as usual, control whether the common prompt is shown, so that if you pass
-Confirm, for instance, you'll get the common confirmation prompt in addition to the extra one, after the latter; in the case of a non-container item (file) or a container that happens to be empty, -Confirm will show only the common prompt.
Note:
Typically, such extra prompts are suppressed with the -Force switch, as in the case of the
Set-ExecutionPolicy cmdlet.
In the context of Remove-Item, however, -Force has a different meaning: it ensures that files or directories that are hidden or files that have the read-only attribute set can be deleted.
Therefore, it is -Recurse that signals the explicit intent to remove a container along with its content, and thereby suppresses the extra prompt.