---
name: Clear-RecycleBin fails silently as SYSTEM
description: Clear-RecycleBin -Force is a no-op when invoked from a SYSTEM-context process (RMM agents, scheduled tasks running as LocalSystem). Returns success but reclaims nothing. Use direct enumeration of C:\$Recycle.Bin\<SID> instead.
type: feedback
---

`Clear-RecycleBin -Force` returns silently without erroring when called from a process that has no interactive desktop session — i.e. SYSTEM-context contexts like the GuruRMM agent, Datto RMM agent, scheduled tasks running as LocalSystem, or any service. The cmdlet wraps the Shell COM `IFileOperation` API which requires an interactive Shell; SYSTEM has none, so the call exits as a no-op. No exception, no warning, no event log entry. The folder size before and after is identical.

**Why:** Hit during ASSISTMAN-PC cleanup 2026-05-08 (Cascades). First cleanup pass reported "Recycle Bin status=cleared" but `Get-FolderSizeMB` showed 12,272 MB before and 12,272 MB after. 12 GB of reclaimable space sitting untouched.

**How to apply:** When writing temp-file / cleanup scripts that will be dispatched via an RMM (GuruRMM, Datto RMM, ScreenConnect Backstage, scheduled tasks as SYSTEM), do not use `Clear-RecycleBin`. Instead enumerate `C:\$Recycle.Bin\<SID>\*` directly across each user SID folder and `Remove-Item -Recurse -Force` on each child, skipping `desktop.ini`. Working pattern saved at `C:\Users\Howard\AppData\Local\Temp\assistman-rb-clean.ps1` (and embedded in the 2026-05-08 ASSISTMAN-PC session log).

If the script needs to run in either context (interactive *or* SYSTEM), still prefer direct enumeration — it works in both, while `Clear-RecycleBin` only works in interactive sessions. One code path, no branching.
