# run this once to setup cleanup tool
cleanmgr /d c: /sageset:1337 /VeryLowDisk /AUTOCLEAN
Write-Host "Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

# scan system
sfc /scannow

#DISM
#First... let's repair what's broken
#dism.exe /Online /Cleanup-Image /RestoreHealth

#Analyze (probably not needed)
#dism.exe /Online /Cleanup-Image /AnalyzeComponentStore

#Delete junk
dism.exe /Online /Cleanup-Image /StartComponentCleanup

#Delete superseded junk
dism.exe /Online /Cleanup-Image /SPSuperseded

#Remove the temp files in AppData\Local\Temp
$tempFilesENV = Get-ChildItem "env:\TEMP"
$tempFiles = $tempFilesENV.Value
Remove-Item -Recurse "$tempFiles\*"

#Remove windows temp files
$windowsTemp = "C:\Windows\Temp\*"
Remove-Item -Recurse "$windowsTemp"

#Remove old Windows Updates
$winDist = "C:\Windows\SoftwareDistribution"
#Note: By removing this you will lose the Updates History and it might 
#redownload everything at the next update if you already haven't installed it
Get-Service -Name WUAUSERV | Stop-Service -Force
Remove-Item -Path $winDist -Recurse -Force
Get-Service -Name WUAUSERV | Start-Service

#Disk Clean up Tool
cleanmgr /sagerun:1337 /VeryLowDisk /AUTOCLEAN | Out-Null

#DISM
#First... let's repair what's broken
#dism.exe /Online /Cleanup-Image /RestoreHealth

#Analyze (probably not needed)
#dism.exe /Online /Cleanup-Image /AnalyzeComponentStore

#Delete junk
dism.exe /Online /Cleanup-Image /StartComponentCleanup

#Delete superseded junk
dism.exe /Online /Cleanup-Image /SPSuperseded

