Remove-Item
Use Remove-Item to delete files, folders, registry keys, or other provider items; -Recurse and -Force clear non-empty trees.
Documentation: Microsoft Learn — Remove-Item
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Remove-Item [-Path] <String[]> [-Recurse] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]- Stage 1Remove-Item
-Path -Recurse -Force -WhatIf -Confirm
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Remove-Item -WhatIf
Show reference output
Sample output · fictional data, shaped like the real thing
What if: Performing the operation "Remove File" on target "C:\Temp\old.log".
Remove-Item -Recurse, then Get-ChildItem to verify
Show reference output
Sample output · fictional data, shaped like the real thing
Directory: C:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/9/2026 1:58 PM 312 new.txt -a---- 10/9/2026 2:14 PM 0 run.log
Note: Remove-Item prints nothing on success — the listing above is Get-ChildItem's output, run afterwards to confirm OldFolder is gone from C:\Temp.
Parameters
Parameter definitions:
-Path-Recurse-Force-WhatIf-Confirm
Practical use and troubleshooting
Practical scenario: Use Remove-Item when you need to delete files, folders, registry keys, or other provider items; -Recurse and -Force clear non-empty trees. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: A directory-not-empty prompt is not a permissions error. Inspect its children and use -Recurse only when those children are intended for deletion; preview supported changes with -WhatIf. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Clear-Content. Clear-Content leaves the item in place but removes its content; Remove-Item deletes the item. Emptying a log and deleting a directory are different operations. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Remove-Item Use Remove-Item to delete files, folders, registry keys, or other provider items; -Recurse and -Force clear non-empty trees.
Next: Get-Item