Remove-Safe is a PowerShell module that provides a safe alternative to Remove-Item. Instead of permanently deleting files and folders, it moves them to the Recycle Bin.
Features:
- Supports wildcards (*, ?)
- Recursive folder deletion (-Recurse)
- Handles hidden and system files (-Force)
Clone the repository or download the files:
> git clone https://github.com/gibosio/Remove-Safe.git
> cd Remove-Safe\Remove-SafeCopy the module to a folder included in your $env:PSModulePath, for example:
> $target = "$env:USERPROFILE\Documents\PowerShell\Modules\Remove-Safe"
> New-Item -ItemType Directory -Force -Path $target
> Copy-Item -Recurse -Path .\* -Destination $targetThen import the module:
> Import-Module Remove-SafeVerify that it loaded correctly:
Get-Command -Module Remove-Safe -CommandType AllYou should see both the function Remove-Safe and its alias trash.
The main command is:
> Remove-Safe -Path <Path> [-Recurse] [-Force]You can also use the alias:
> trash <Path> [-Recurse] [-Force]-
-Path
One or more paths to move to the Recycle Bin. Supports wildcards (*, ?) and comma-separated lists. -
-Recurse
Removes a folder and all its contents recursively. -
-Force
Includes hidden and system files. -
-WhatIf -Confirm
Remove a single file:
> Remove-Safe .\file.txtor
> trash .\file.txtRemove multiple files:
> Remove-Safe file1.txt, file2.txt
> trash file1.txt, file2.txtRemove a folder and all its contents:
> Remove-Safe C:\ToBeDeleted -Recurse
> trash C:\ToBeDeleted -RecurseUse wildcards:
> Remove-Safe C:\tobedele?ed*
> trash C:\tobedele?ed*- Folders specified without -Recurse will not be removed unless the option is explicitly provided.
- If a path does not match any file or folder, a warning will be displayed.
- If an item cannot be moved to the Recycle Bin, a warning will be shown.
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is licensed under the GNU GPL v3. See https://www.gnu.org/licenses/gpl-3.0.html for details.