function Create-ScheduledTask $taskName = "WindowsTempCleaner" $scriptPath = $MyInvocation.MyCommand.Path
function Format-FileSize param($SizeInMB) if ($SizeInMB -ge 1024) return "0:N2 GB" -f ($SizeInMB / 1024) else return "0:N2 MB" -f $SizeInMB windows 11 clear temp files
# 4. Recent Files $recent = "$env:APPDATA\Microsoft\Windows\Recent" $locations += @Path = $recent; Name = "Recent Files" windows 11 clear temp files
function Get-FolderSize param($Path) try $colItems = Get-ChildItem $Path -Recurse -Force -ErrorAction SilentlyContinue catch return 0 windows 11 clear temp files
Write-Host "" Write-Host "Total space freed: $(Format-FileSize $totalFreed)" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan
switch ($choice) "1" Clear-TempFiles "2" Create-Shortcut "3" Create-ScheduledTask "4" exit default Write-Host "Invalid option" -ForegroundColor Red
Windows 11 has a robust, built-in "Storage Sense" tool that categorizes files, making it easy to see exactly what you are deleting.