Clear RecycleBin - PowerShell
Overview
Clear-RecycleBin securely removes all items from the Recycle Bin, freeing up disk space. This command is useful for purging confidential data or reclaiming storage on local or remote drives.
Syntax
Clear-RecycleBin [-Confirm] [-Drive <String[]>] [-Verbose]
Options/Flags
- Confirm: Prompts for confirmation before executing the command.
- Drive: Specify one or more drives to clear their Recycle Bin. Defaults to the current drive.
- Verbose: Displays detailed status messages during execution.
Examples
Simple Usage:
Clear-RecycleBin
Clearing Specific Drives:
Clear-RecycleBin -Drive C: -Drive D:
Verbose Output:
Clear-RecycleBin -Verbose
Common Issues
- Access Denied: If you encounter access denied errors, check if you have sufficient permissions to access the Recycle Bin on the specified drives.
- Data Loss: Using this command will permanently delete items from the Recycle Bin. Exercise caution before executing it.
Integration
The Clear-RecycleBin command can be combined with other PowerShell commands to automate cleanup tasks:
Get-Item "C:\Users\*\RecycleBin\$RECYCLE.BIN" | Clear-RecycleBin
Related Commands
- New-Item: Creates a directory or file.
- Remove-Item: Deletes files or directories.
- Get-Item: Gets items from the file system, including the Recycle Bin.