Search code examples
powershellbatch-filewindows-7recycle-bin

How to empty recycling bin in batch


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.


Solution

  • 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}"