Windows 11 - Clear Temp Files New!

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`" -Silent" $trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Sunday -At 3am $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest

foreach ($loc in $locations) if ($loc.Path -eq "RecycleBin") # Handle Recycle Bin separately $size = Get-RecycleBinSize if (-not $Silent) Write-Host "Checking $($loc.Name)..." -ForegroundColor Yellow if (-not $Silent) Write-Host " Size: $(Format-FileSize $size)" -ForegroundColor Gray if ($size -gt 0 -and (-not $Silent)) $confirm = Read-Host " Clear Recycle Bin? (Y/N)" if ($confirm -eq 'Y') Clear-RecycleBin -Force -ErrorAction SilentlyContinue $totalFreed += $size $results += [PSCustomObject]@Location = $loc.Name; Freed = $size if (-not $Silent) Write-Host " ✓ Cleared $(Format-FileSize $size)" -ForegroundColor Green elseif ($size -gt 0 -and $Silent) Clear-RecycleBin -Force -ErrorAction SilentlyContinue $totalFreed += $size elseif (Test-Path $loc.Path) $size = Get-FolderSize $loc.Path if (-not $Silent) Write-Host "Checking $($loc.Name)..." -ForegroundColor Yellow if (-not $Silent) Write-Host " Size: $(Format-FileSize $size)" -ForegroundColor Gray if ($size -gt 0 -and (-not $Silent)) $confirm = Read-Host " Clear this folder? (Y/N/A - All)" if ($confirm -eq 'Y' -or $confirm -eq 'A') $freed = Clean-Folder $loc.Path $totalFreed += $freed $results += [PSCustomObject]@Location = $loc.Name; Freed = $freed if (-not $Silent) Write-Host " ✓ Cleared $(Format-FileSize $freed)" -ForegroundColor Green if ($confirm -eq 'A') $Silent = $true elseif ($size -gt 0 -and $Silent) $freed = Clean-Folder $loc.Path $totalFreed += $freed else if (-not $Silent) Write-Host "Skipping $($loc.Name) (not found)" -ForegroundColor DarkGray if (-not $Silent) Write-Host "" windows 11 clear temp files

Write-Host "Desktop shortcut created!" -ForegroundColor Green function Create-ScheduledTask $taskName = "WindowsTempCleaner" $scriptPath = $MyInvocation.MyCommand.Path $action = New-ScheduledTaskAction -Execute "powershell

# 4. Recent Files $recent = "$env:APPDATA\Microsoft\Windows\Recent" $locations += @Path = $recent; Name = "Recent Files" Name = "Recent Files"