I'm building an script in PowerShell that runs via an RMM tool, so it executes in the SYSTEM context. The goal is to automatically delete files from the Recycle Bin that are older than 30 days, for all user accounts on a Windows 10/11 system.
I've tried:
Iterating through
C:\$Recycle.Bin\S-1-5-...SID foldersFiltering
$I*and$R*files usingLastWriteTimeUsing
Shell.Application.Namespace(0xA)(only works for the interactive user, not SYSTEM)Testing with full permissions and recursion
Problems:
Even when files are present in the Recycle Bin, nothing gets deleted
LastWriteTimedoesn’t reliably reflect the deletion dateSYSTEM has access but can't determine which files are old enough
No clear or consistent metadata to filter on
Is there any reliable way to clean up Recycle Bin files older than 30 days across all users from a non-interactive SYSTEM context?
