How to Force ‘Remove-Item’ to Delete Items and Suppress the Confirmation Prompt in Windows PowerShell

The Problem:

In Windows Powershell, deleting items with Remove-Item causes a confirmation prompt to stop a script from functioning. The prompt says:


The item at [path] has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Areyou sure you want to continue?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”)

The Solution:

Run Remove-Item with the -recurse switch.

Remove-Item C:pathtofile -recurse

Now your script will run with no intervention necessary.

The Long Story:

There is considerable confusion about how to supress confirmation prompts with Remove-Item. It’s rather silly since the solution is right in the confirmation wording (I am guilty of being silly since I didn’t see that at first either). Here are some false ways of performing this task along with why they are false:

Using the -Confirm parameter.

Some people will suggest that you use the following line:

Remove-Item c:pathtofile -Confirm:$false

However, -confirm is set to $false by default and furthermore it has nothing to do with the warning above. The -confirm parameter “prompts you for confirmation before executing the command.” In the above scenario, I’m not being prompted before running the command, I’m being prompted to confirm the deletion of a file that has child objects.

For more information abuot the -confirm parameter, run the following command in a PowerShell prompt:

get-help about_CommonParameters

Using the -force switch

This does not “force” the Remove-Item cmdlet to delete files in the face of a confirmation prompt. This forces the deletion of hidden and read only items.


  1. Ricardo Trigueiro

    March 18, 2014 at 4:51 am


    U’re the man!!!

    The -Recurse works perfect!!!


  2. Ventrex

    June 10, 2014 at 10:20 pm

    Thanks! I was looking for this but then for Remove-ItemProperty. The -recurse doesn’t work there but the -Confirm:$false did! Now i can sillently remove unneeded registry keys.


Leave a Reply

Your email address will not be published. Required fields are marked *

Follow TheNubbyAdmin!

follow us in feedly

Raw RSS Feed:

Contact Me!

Want to hire me as a consultant? Have a job you think I might be interested in? Drop me a line:

Contact Me!

Subscribe via Email

Your email address is handled by Google FeedBurner and never spammed!

The Nubby Archives

Circle Me on Google+!

Photos from Flickr

Me on StackExchange

The IT Crowd Strava Group