Home » PowerShell Tips » PowerShell Empty Recycle Bin

PowerShell Empty Recycle Bin

When you delete the files or folders, they are moved to the Recycle Bin, where they can be easily restored if needed. However, if you want to free up disk space and permanently remove deleted items, you must empty the recycle bin.

It’s easier to clear recycle bin files or folder using the GUI, right-click on the Recycle Bin folder and selects delete. It will clear all the contents.

You can empty the recycle bin on a local or remote computer with a PowerShell script efficiently.

To empty the recycle bin in PowerShell, use the Clear-RecycleBin cmdlet. The PowerShell Clear-RecycleBin command will clear the contents of the recycle bin.

PowerShell Empty Recycle Bin
PowerShell Empty Recycle Bin

In this article, we will discuss how to empty the recycle bin locally and empty the recycle bin for specified drives using PowerShell.

PowerShell Clear-RecycleBin Syntax

The syntax to clear the recycle bin in PowerShell is given below.

Clear-RecycleBin
     [[-DriveLetter] <String[]>]
     [-Force]
     [-WhatIf]
     [-Confirm]
     [<CommonParameters>]

How to Empty All Recycle Bin with PowerShell

You can forcefully empty all recycle bins on the local computer without asking the user for confirmation to delete recycle bin content using the Clear-RecycleBin cmdlet as below.

Clear-RecycleBin -Force

In the above script, PowerShell Clear-RecycleBin uses Force parameter to remove the contents of all recycle bins without user confirmation.

How to Empty Recycle Bin with Confirmation in PowerShell

If you want to empty the recycle bin on your local computer, use the below command.

Clear-RecycleBin

The above command in PowerShell to empty all recycle bins on the local computer asks for user confirmation to delete the contents of the recycle bin.

PS C:\> Clear-RecycleBin

Confirm
Are you sure you want to perform this action?
Performing the operation "Clear-RecycleBin" on target "All of the contents of the Recycle Bin".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Upon Yes or yes to All consent, it will empty all recycle bins on the local computer.

Cool Tip: How to convert decimal to hex in PowerShell!

How to Clear Recycle Bin of Specified Drive in PowerShell

To clear the recycle bin of the specified drive eg… C:\, use the Clear-RecycleBin command with the -DriveLetter parameter.

Clear-RecycleBin -DriveLetter C

In the above script, PowerShell Clear-RecycleBin uses DriveLetter parameter to specify the drive letter as C. It will ask for user confirmation to empty recycle bins of C Drive only.

The output of above command to delete recycle bin contents of the specified drive as below

PS C:\> Clear-RecycleBin -DriveLetter C

Confirm
Are you sure you want to perform this action?
Performing the operation "Clear-RecycleBin" on target "All of the contents of the Recycle Bin for the 'C:\' drive".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

PS C:\>

Cool Tip: How to stop the running process in PowerShell!

Conclusion

In the above article, we have learned how to empty recycle bins using a PowerShell script, and empty all recycle bins on a local computer.

PowerShell Clear-RecycleBin cmdlet clears the contents of the recycle bin. You can delete the content of a specified drive using the DriveLetter parameter.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.