PowerShell Genie

Remove-Item

Use Remove-Item to delete files, folders, registry keys, or other provider items; -Recurse and -Force clear non-empty trees.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Remove-Item

Syntax

1PS> Remove-Item [-Path] <String[]> [-Recurse] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
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>]
  1. Stage 1Remove-Item-Path -Recurse -Force -WhatIf -Confirm

    Try it

    Windows PowerShell

    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.

    Interactive simulation · fictional data

    Examples

    Remove-Item -WhatIf

    1PS> Remove-Item C:\Temp\old.log -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

    1PS> Remove-Item C:\Temp\OldFolder -Recurse
    2PS> Get-ChildItem C:\Temp
    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

    Remove-Item on Microsoft Learn

    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.

    Remove-Item reference on Microsoft Learn

    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
    Genie guideRemove-Item

    Use Remove-Item to delete files, folders, registry keys, or other provider items; -Recurse and -Force clear non-empty trees. The console below is pre-loaded — run it, then change a value and run it again.