How to empty recycling bin in batch

09stephenb picture 09stephenb · Jan 14, 2014 · Viewed 10.2k times · Source

I need a code to empty the recycling bin without conformation I have tried the simple del $Recycle.Bin but it says access denied even when elevated does any one know a code I could use.

Answer

Knuckle-Dragger picture Knuckle-Dragger · Jan 14, 2014

This emptied my bin without any confirmation.

@ECHO OFF
start /b /wait powershell.exe -command "$Shell = New-Object -ComObject Shell.Application;$RecycleBin = $Shell.Namespace(0xA);$RecycleBin.Items() | foreach{Remove-Item $_.Path -Recurse -Confirm:$false}"