Skip to content

Extend support for the file-system recycle bin / trash #6801

Open

Description

#6778 tracks porting the Clear-RecycleBin cmdlet to PowerShell Core, and it would be helpful to support other recycle-bin/trash-related functionality too, notably the ability to move filesystem items there.

Note:

  • Windows calls the transient storage area for deleted-via-File Explorer files and folders the recycle bin. In the world of macOS and Linux, the same concept is known as the trash.
    As a real-world metaphor trash makes more sense, because recovering an item from this storage area is not an act of recycling.
    The rest of this post uses the term trash, but it's worth creating aliases so as to offer command and parameter names familiar on all supported platforms.

  • In the Linux world, only distros with freedesktop.org-compliant desktop environments have a standardized trash interface, most easily accessibly via CLIs, as shown in Need port Clear-RecycleBin cmdlet #6778.

Support for moving (sending) filesystem items to the trash

As suggested by @geelaw, we could add a -ToRecycleBin / -ToTrash switch to the FileSystem provider's implementation of the Remove-Item cmdlet.

Ilya (@iSazonov) suggests complementing the new switch with a preference variable that sends items to the trash by default.
The alternative is to use the generic $PSDefaultParameterValues mechanism:
$PSDefaultParameterValues['Remove-Item:ToTrash']=$True

Support for recovering items from the trash.

Programmatically recovering items from the trash is nontrivial and the question is whether programmatic support for it is needed at all (say, via a Recover-Item cmdlet).

Ji Luo (@GeeLaw)'s thoughts:

One possible way for this is to let the cmdlet return a set of recycled items, where each item has an identifier (consistent across invocations but platform-dependent), date of removal, restoration path (sometimes might be unavailable) etc., and another cmdlet would restore items. I would suggest not having such cmdlets.

There's also the issue of feasibility - do all platforms have enough API / CLI support to support such a cmdlet?
On Windows, we can use (New-Object -ComObject Shell.Application).NameSpace(0xA).Items()

Support for opening the trash-folder GUI

Recovering items from the trash is typically done interactively, via the platform's file manager's GUI.

A cmdlet such as Show-RecycleBin / Show-Trash could facilitate that.

That said, perhaps such functionality doesn't add enough value to warrant implementation as a cmdlet, given that users can simply use the respective platform's GUI file manager and, as Ji Luo (@GeeLaw) points out, GUI-focused cmdlets are rare in PowerShell (and are typically only useful in command-line use).

Environment data

Written as of:

PowerShell Core v6.0.2

Activity

  1. iSazonov commented on May 2, 2018

    @iSazonov
    Collaborator

    What about a preference variable to set remove to trash by default without -ToTrash?

  2. mklement0 commented on May 2, 2018

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): Good idea; I've added your suggestion to the OP, but note that we could get away with
    $PSDefaultParameterValues['Remove-Item:ToTrash']=$True

  3. GeeLaw commented on May 2, 2018

    @GeeLaw

    Ilya (@iSazonov) I was about to post what Michael Klement (@mklement0) said. Side-note: it seems that PSDefaultParameterValues is not hierarchical. For VerbosePreference, it is possible to set a local version of it without affecting outer-scoped preference. However, it is not the same with PSDefaultParameterValues.

    It doesn't seem to worth adding a preference variable just for removing items in the file system -- existing preference variables are all widely applicable (whenever the advanced function/script has CmdletBinding, and further, whenever it SupportsShouldProcess).

  4. added
    Issue-Enhancement
    WG-Cmdlets
    on May 2, 2018
  5. fowl2 commented on Jul 12, 2018

    @fowl2

    Various other PSDriveProviders have a "Trash" / soft delete concept - eg. AD (Recycle Bin, Tombstoning), Exchange (Soft delete), SharePoint (two stage recycle bin) - but as with files the "restore" operation is much harder to generalise between providers.

    Restore-Item (or is it Undo-Item?) does sounds fun though =]

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. added
    Resolution-No Activity
    on Nov 16, 2023
  9. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  10. added
    WG-NeedsReview
    and removed
    Resolution-No Activity
    on Mar 4, 2026
  11. kilasuit commented on Mar 4, 2026

    @kilasuit
    Collaborator

    Reopening use to linked issue

    For Recycling I think we can add to Remove-Item a parameterRecycle (aliased as Trash) as opposed to ToRecycleBin or ToTrash as suggested in the op.

    As for Restore-Item this would need more thought to complete but would be a good improvement if possible.

  12. doctordns commented on Mar 18, 2026

    @doctordns
    Collaborator

    I've been bitten badly by PowerShell's lack of support for the recycle bin over the years. I would very much support any mechanism to get PowerShell to use this. I would prefer to see Remove-Item use the recyclebin/trash by default. Perhaps a -deleteforreal parameter to nuke the files permanently. The default should be the safest and a parameter used to override.

  13. moved this from Queue to In-Progress-Issues in Cmdlets Working Groupon Jun 17, 2026
  14. SteveL-MSFT commented on Jun 17, 2026

    @SteveL-MSFT
    Member

    The @PowerShell/wg-powershell-cmdlets discussed this. Since we already have Clear-RecycleBin only for Windows, we would support adding a -ToRecycleBin parameter only for Windows to Remove-Item.

  15. moved this from In-Progress-Issues to Reviewed in Cmdlets Working Groupon Jun 17, 2026
  16. added
    Up-for-Grabs
    WG-Reviewed
    and removed
    WG-NeedsReview
    on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementUp-for-GrabsWG-CmdletsWG-Reviewed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions