The Problem:
In Windows Powershell, deleting items with Remove-Item causes a confirmation prompt to stop a script from functioning. The prompt says:
Confirm
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.








About the Author
I am a self employed Systems Administrator in sunny Phoenix, Arizona. I like origami and lemons. I do not like hangnails or snow. Interested in hiring me? Check the blog sidebar to the right for a contact form or email me at [email protected]