User Tools

Site Tools


generic_disk_cleanup

This is an old revision of the document!


Ejecutar como administrador la consola antes de correr esto

powershell
# Define the recycle bin variable
#The "Namespace(0xA) is defined as the recycle bin. 
#I will add an article soon with all namespaces that you might need. 
$recycleBinShell = New-Object -ComObject Shell.Application
$recycleBinFolder = $recycleBinShell.Namespace(0xA)

# Define windows && users temp && windows prefetch folders
$tempfolders = @(“C:\Windows\Temp\*”, “C:\Windows\Prefetch\*”, “C:\Users\*\Appdata\Local\Temp\*”)

#Finally I want to define the Windows Software Distribution Folder
$winDist = "C:\Windows\SoftwareDistribution"

#Now the magic begins

#Remove items from the recycle bin
$recycleBinFolder.item() | %{Remove-Item $_.path -Recurse -Confirm:$false}

# Empty the recycle bin for all users
rd /s "c:\$Recycle.Bin"

# Remove temp && prefetch files
Remove-Item $tempfolders -force -recurse

# Remove old wu downloads
net stop wuauserv
Rename-Item $winDist         SoftwareDistribution.old
net start wuauserv
Rmdir C:\Windows\SoftwareDistribution.old -recurse

#DISM
#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

# Run disk Cleanup app in silent mode
cleanmgr /sagerun:1 /autoclean | out-Null
generic_disk_cleanup.1672083429.txt.gz · Last modified: 2024/10/17 21:42 (external edit)