Repository navigation
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.2Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReviewed
Activity
iSazonov commentedon May 2, 2018
What about a preference variable to set remove to trash by default without
-ToTrash?mklement0 commentedon May 2, 2018
Ilya (@iSazonov): Good idea; I've added your suggestion to the OP, but note that we could get away with
$PSDefaultParameterValues['Remove-Item:ToTrash']=$TrueGeeLaw commentedon May 2, 2018
Ilya (@iSazonov) I was about to post what Michael Klement (@mklement0) said. Side-note: it seems that
PSDefaultParameterValuesis not hierarchical. ForVerbosePreference, it is possible to set a local version of it without affecting outer-scoped preference. However, it is not the same withPSDefaultParameterValues.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 itSupportsShouldProcess).fowl2 commentedon Jul 12, 2018
Various other
PSDriveProvidershave 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 itUndo-Item?) does sounds fun though =]microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
kilasuit commentedon Mar 4, 2026
Reopening use to linked issue
For Recycling I think we can add to Remove-Item a parameter
Recycle(aliased as Trash) as opposed toToRecycleBinorToTrashas suggested in the op.As for Restore-Item this would need more thought to complete but would be a good improvement if possible.
doctordns commentedon Mar 18, 2026
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-Itemuse the recyclebin/trash by default. Perhaps a-deleteforrealparameter to nuke the files permanently. The default should be the safest and a parameter used to override.SteveL-MSFT commentedon Jun 17, 2026
The @PowerShell/wg-powershell-cmdlets discussed this. Since we already have
Clear-RecycleBinonly for Windows, we would support adding a-ToRecycleBinparameter only for Windows toRemove-Item.