# 2. System Temp $systemTemp = "$env:SystemRoot\Temp" $locations += @Path = $systemTemp; Name = "System Temp"
function Format-FileSize param($SizeInMB) if ($SizeInMB -ge 1024) return "0:N2 GB" -f ($SizeInMB / 1024) else return "0:N2 MB" -f $SizeInMB
# 5. Recycle Bin $locations += @Path = "RecycleBin"; Name = "Recycle Bin"
return $totalFreed
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Force
$totalFreed = 0 $locations = @()
$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
# 2. System Temp $systemTemp = "$env:SystemRoot\Temp" $locations += @Path = $systemTemp; Name = "System Temp"
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
# 5. Recycle Bin $locations += @Path = "RecycleBin"; Name = "Recycle Bin" windows 11 clear temp files
return $totalFreed
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Force windows 11 clear temp files
$totalFreed = 0 $locations = @()
$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