Recycle Bin Emptying Using Powershell

Background

One might find that the Recycle Bin is taking up a good chuck of storage.

Remediation

Powershell

Let us use Powershell to dump our recycle bins.

Cmdlet :- Clear-RecycleBin

Syntax

Here is the Syntax

Clear-RecycleBin-Syntax

Sample

All Drives
Script
Clear-RecycleBin  -Force
Output

force.20181124.1008AM.PNG

Drive Letters Specified
Script
Clear-RecycleBin  -DriveLetter "C", "D","E"
Output

foldersSpecified.20181124.0950AM.PNG

Confirm
Confirm – True
Script
Clear-RecycleBin  -Confirm:$true
Output

confirmTrue.20181124.0955AM

Explanation
  1. Prompted
Confirm – False
Script
Clear-RecycleBin  -Confirm:$false
Output

confirmFalse.20181124.0957AM.PNG

Explanation
  1. Not Prompted

Errors

Error :- Clear-RecycleBin : The system cannot find the file specified
Sample

Clear-RecycleBin -Confirm:$false -DriveLetter "C", "D","E"

Output – Image

error.cannotFindtheFileSpecified.20181124.1030AM

Output – Textual

Clear-RecycleBin : The system cannot find the file specified
At line:1 char:1
+ Clear-RecycleBin -Confirm:$false -DriveLetter "C", "D","E"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (RecycleBin:String) [Clear-RecycleBin], Win32Exception
+ FullyQualifiedErrorId : FailedToClearRecycleBin,Microsoft.PowerShell.Commands.ClearRecycleBinCommand

Overlook

Try to use “-ErrorAction SilentlyContinue


Clear-RecycleBin -Confirm:$false -DriveLetter "C", "D","E"  -ErrorAction SilentlyContinue

Dedicated

Dedicated to Gee Law

Gee Law

Blog Posts & Git Hub Issues

  1. GeeLaw.blog
    • PowerShell codebase misuses SHEmptyRecycleBin function in Clear-RecycleBin cmdlet
      Link
  2. GitHub
    • PowerShell
      • Misuse of `SHEmptyRecycleBin` in `Clear-RecycleBin` cmdlet #6743Link

Sidenotes

Link
Sidenote
 I wish Raymond Chen could write a blog entry on SHEmptyRecycleBin if there’s something interesting to add. He’s an expert of Windows shell programming. However, his suggestion box is currently closed and there’s no prescribed way to make a suggestion (though I could have sent him an email, but that would be too impolite), so I can only make wishes.

One thought on “Recycle Bin Emptying Using Powershell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s