PowerShell - Delete files and directories using using Remove-Item

by
Jeremy Canfield |
Updated: May 17 2023
| PowerShell articles
This is the most basic form of the command to delete a directory using PowerShell.
Remove-Item "C:\Path\To\Directory"
Some directories contain subdirectories. The -recurse option can be used to delete every file and directory below the specified directory.
Remove-Item -recurse "C:\Path\To\Directory"
Let's say Remove-Item returns something like Permission Denied. In this scenario, let's use Get-Item to check the item permissions.
Get-Item C:\Temp\example.txt
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 7/26/2024 9:28 AM 80 example.txt
Some directories contain secured files or system files. The -force flag can be used to try to delete files and directories that fail to be deleted without the -force flag.
Remove-Item -recurse -force "C:\Path\To\Directory"
Did you find this article helpful?
If so, consider buying me a coffee over at