Tag Archives: Clear-RecycleBin

Get-RecycleBin – Shows the contents of the Recycle Bin

As I posted earlier in the Clear-RecycleBin New PowerShell 5.0 cmdlet, available in Windows 10 article, in Windows 10 it is now possible to clear the Recycle Bin. Because the functionality to actually view which files is not implemented in any cmdlet at the moment I decided to upload a new function, Get-RecycleBin, to the TechNet Script Gallery.

Get-RecycleBin

Using the this function it is possible to view the contents of the recycle bin, including the filename, size and the current path in the Recycle Bin folder.

.EXAMPLE
Get-RecycleBin

Description
-----------
Executing this function will display the name, size and path of the files stored in the Recycle Bin for the current user

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
JaapBrasser.com – Scripts
Get-RecycleBin – shows the contents of the Recycle Bin
Share

Clear-RecycleBin New PowerShell 5.0 cmdlet, available in Windows 10

In PowerShell 5.0 a new cmdlet has been introduced that provides the ability to clear the Recycle Bin programmatically. It supports the following four parameters:

  1. DriveLetter
  2. Force
  3. WhatIf
  4. Confirm

Unfortunately there is no Get-RecycleBin cmdlet, for this purpose I have written a short function that enumerates the contents of Recycle Bin for the current user:

1
2
3
4
Function Get-RecycleBin {
    (New-Object -ComObject Shell.Application).NameSpace(0x0a).Items() |
	Select-Object Name,Size,Path
}

Get-RecycleBin

By verifying this output we can now determine if we would like to Clear the Recycle Bin or if some files that are stored there should be recovered before deleting all files. The following command will delete all files from the Recycle Bin for all drive letters:

1
Clear-RecycleBin

Clear-RecycleBin

The default mode of operation of this cmdlet is to ask for confirmation before deleting all files. This is similar behavior to right clicking the icon of Recycle Bin and clicking ‘Empty Recycle Bin’. To delete the files without confirmation the following code can be used:

1
Clear-RecycleBin -Force

Alternatively the Confirm parameter can also be explicitly set to $false:

1
Clear-RecycleBin -Confirm:$false

Unfortunately there is no online help available for this cmdlet, so for more information about this cmdlet please refer to the built-in help in PowerShell:

1
Get-Help Clear-RecycleBin -ShowWindow

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
Get-RecycleBin – shows the contents of the Recycle Bin
Share