When using PowerShell Remove-Item to remove a directory that is not empty, it asks for confirmation:
PS C:\Users\<redacted>\Desktop\Temp> Remove-Item .\Test Confirm The item at C:\Users\<redacted>\Desktop\Temp\Test 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"):
If I run powershell in non-interactive mode, I get an error instead:
Remove-Item : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. At line:1 char:1 + Remove-Item .\Test + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-Item], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemoveItemCommand
I know that I can use -Recurse so that the Remove-Item continues as if I selected the Yes option. Can I somehow act as if I chose the No option?
(Just for clarity: -Force and -Confirm:$false not what I want here.)
powershell
Fabian schmied
source share