PowerShell: Empty Recycle Bin
March 13, 2013 3 Comments
Here is a quick PowerShell script I found recently to clear the Windows Recycle Bin. This can be really useful if you want to automatically empty the Recycle Bin through something like the Task Scheduler. This code comes from the TechNet Script Center, courtesy of Windows Engineer and PowerShell Blogger Rich Prescott.
$Shell = New-Object -ComObject Shell.Application $RecBin = $Shell.Namespace(0xA) $RecBin.Items() | %{Remove-Item $_.Path -Recurse -Confirm:$false}
This script allows you to view the contents of the recycle bin in your profile. The first line creates a ComObject and then the second line grabs the Recycling Bin special folder. It then enumerates the items contained in that special folder and removes each of them. The Remove-Item cmdlet includes a switch to turn off confirmation for the removal of the files. It can be removed if you would like to be prompted for each file.
Works on:
Windows Server 2012 and Up | Yes | Windows 10 and Up | Yes |
Windows Server 2008 R2 | Yes | Windows 8 | Yes |
Windows Server 2008 | Yes | Windows 7 | Yes |
Windows Server 2003 | No | Windows Vista | Yes |
Windows XP | Yes | ||
Windows 2000 | No |