Skip to content

Commit b3d7eff

Browse files
committed
Added Disk cleanup scripts
- Remove-TemporaryFiles - Remove-WindowsOld - Start-DiskCleanUp *NOTE: These are not integrated with the Apply Tweaks button as some of then delete occurring install/update files and should be done separately or while you're aware
1 parent e16fb20 commit b3d7eff

4 files changed

+107
-3
lines changed

WinDebloatTools.ps1

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Learned from: https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.1
1+
# Learned from: https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.1
22
# Adapted majorly from https://github.com/ChrisTitusTech/win10script and https://github.com/Sycnex/Windows10Debloater
33
# Take Ownership tweak from: https://www.howtogeek.com/howto/windows-vista/add-take-ownership-to-explorer-right-click-menu-in-vista/
44

@@ -177,7 +177,10 @@ function Show-GUI() {
177177
$ClDebloatTools = New-Label -Text "System Debloat Tools" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.CaptionLabelHeight -LocationX $LayoutT1.PanelElementX -LocationY 0 -FontSize $LayoutT1.Heading[2] -FontStyle 'Bold'
178178
$ApplyTweaks = New-Button -Text "Apply Tweaks" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -ElementBefore $ClDebloatTools -FontSize $LayoutT1.Heading[3] -FontStyle 'Bold' -ForeColor $Colors.Cyan
179179
$UndoTweaks = New-Button -Text "Undo Tweaks" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $ApplyTweaks -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
180-
$RemoveMSEdge = New-Button -Text "Remove Microsoft Edge" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $UndoTweaks -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
180+
$DiskCleanUp = New-Button -Text "Run a Disk Cleanup" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $UndoTweaks -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.Cyan
181+
$RemoveTemporaryFiles = New-Button -Text "Remove Temporary Files" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $DiskCleanUp -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.Cyan
182+
$RemoveWindowsOld = New-Button -Text "Remove Windows.old Folder" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $RemoveTemporaryFiles -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
183+
$RemoveMSEdge = New-Button -Text "Remove Microsoft Edge" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $RemoveWindowsOld -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
181184
$RemoveOneDrive = New-Button -Text "Remove OneDrive" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $RemoveMSEdge -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
182185
$RemoveXbox = New-Button -Text "Remove Xbox" -Width $LayoutT1.PanelElementWidth -Height $LayoutT1.ButtonHeight -LocationX $LayoutT1.PanelElementX -FontSize $LayoutT1.Heading[3] -ElementBefore $RemoveOneDrive -MarginTop $LayoutT1.DistanceBetweenElements -ForeColor $Colors.WarningYellow
183186
$PictureBox1 = New-PictureBox -ImageLocation "$PSScriptRoot\src\assets\script-image.png" -Width $LayoutT1.PanelElementWidth -Height (($LayoutT1.ButtonHeight * 4) + ($LayoutT1.DistanceBetweenElements * 4)) -LocationX $LayoutT1.PanelElementX -ElementBefore $RemoveXbox -MarginTop $LayoutT1.DistanceBetweenElements -SizeMode 'Zoom'
@@ -458,7 +461,7 @@ function Show-GUI() {
458461
$TabSoftwareInstall.Controls.AddRange(@($TlSoftwareInstall, $ClSoftwareInstall, $T2PanelPackageManagersSettings, $T2Panel1, $T2Panel2, $T2Panel3, $T2Panel4))
459462
# Add Elements to each Tab Panel
460463
$T1Panel1.Controls.AddRange(@($ClCustomizeFeatures, $CbDarkTheme, $CbActivityHistory, $CbBackgroundsApps, $CbClipboardHistory, $CbClipboardSyncAcrossDevice, $CbCortana, $CbHibernate, $CbLegacyContextMenu, $CbOldVolumeControl, $CbOnlineSpeechRecognition, $CbPhoneLink, $CbPhotoViewer, $CbSearchAppForUnknownExt, $CbTelemetry, $CbXboxGameBarDVRandMode))
461-
$T1Panel2.Controls.AddRange(@($ClDebloatTools, $ApplyTweaks, $UndoTweaks, $RemoveMSEdge, $RemoveOneDrive, $RemoveXbox, $PictureBox1))
464+
$T1Panel2.Controls.AddRange(@($ClDebloatTools, $ApplyTweaks, $UndoTweaks, $DiskCleanUp, $RemoveTemporaryFiles, $RemoveWindowsOld, $RemoveMSEdge, $RemoveOneDrive, $RemoveXbox, $PictureBox1))
462465
$T1Panel2.Controls.AddRange(@($ClInstallSystemApps, $InstallDolbyAudio, $InstallMicrosoftEdge, $InstallOneDrive, $InstallPaintPaint3D, $InstallPhoneLink, $InstallQuickAssist, $InstallSoundRecorder, $InstallTaskbarWidgets, $InstallUWPWMediaPlayer, $InstallXbox))
463466
$T1Panel2.Controls.AddRange(@($ClOtherTools, $RandomizeSystemColor, $ReinstallBloatApps, $RepairWindows, $ShowDebloatInfo))
464467
$T1Panel3.Controls.AddRange(@($ClWindowsUpdate, $CbAutomaticWindowsUpdate))
@@ -530,6 +533,18 @@ function Show-GUI() {
530533
$Form.Update()
531534
})
532535

536+
$DiskCleanUp.Add_Click( {
537+
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts @("Start-DiskCleanUp.ps1") -DoneTitle $DoneTitle -DoneMessage $DoneMessage
538+
})
539+
540+
$RemoveTemporaryFiles.Add_Click( {
541+
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts @("Remove-TemporaryFiles.ps1") -DoneTitle $DoneTitle -DoneMessage $DoneMessage
542+
})
543+
544+
$RemoveWindowsOld.Add_Click( {
545+
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts @("Remove-WindowsOld.ps1") -DoneTitle $DoneTitle -DoneMessage $DoneMessage
546+
})
547+
533548
$RemoveMSEdge.Add_Click( {
534549
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts @("Remove-MSEdge.ps1") -DoneTitle $DoneTitle -DoneMessage $DoneMessage
535550
})

src/scripts/Remove-TemporaryFiles.ps1

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
2+
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemVerified.psm1"
3+
4+
function Remove-TemporaryFiles() {
5+
$TweakType = "Temp"
6+
7+
Write-Status -Types "+", $TweakType -Status "Cleaning the $env:SystemRoot\Temp\ folder..."
8+
Remove-ItemVerified -Path "$env:SystemRoot\Temp\*" -Recurse -Force
9+
Write-Status -Types "+", $TweakType -Status "Cleaning the $env:TEMP\ folder..."
10+
Remove-ItemVerified -Path "$env:TEMP\*" -Recurse -Force
11+
}
12+
13+
Remove-TemporaryFiles

src/scripts/Remove-WindowsOld.ps1

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
2+
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\ui\Show-MessageDialog.psm1"
3+
4+
function Remove-WindowsOld() {
5+
$TweakType = "Windows.old"
6+
7+
Write-Status -Types "+", $TweakType -Status "Cleaning up Old Windows Installation (Windows.old)..."
8+
Start-Process cleanmgr.exe -ArgumentList "/d $env:SystemDrive", "/AUTOCLEAN"
9+
}
10+
11+
$Ask = "Are you sure you want to remove $env:SystemDrive\Windows.old?`nOnly do this AFTER you have moved all your data from there.`n`nList from a few folders:`n- $env:SystemDrive\Windows.old\Users\$env:USERNAME\[...]`n - AppData`n - Desktop`n - Documents`n - Downloads`n - Music`n - Pictures`n - Videos`n- $env:SystemDrive\Windows.old\ProgramData"
12+
13+
switch (Show-Question -Title "Warning" -Message $Ask -BoxIcon "Warning") {
14+
'Yes' {
15+
Remove-WindowsOld
16+
}
17+
'No' {
18+
Write-Host "Aborting..."
19+
}
20+
'Cancel' {
21+
Write-Host "Aborting..." # With Yes, No and Cancel, the user can press Esc to exit
22+
}
23+
}

src/scripts/Start-DiskCleanUp.ps1

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
2+
3+
function Start-DiskCleanUp() {
4+
[CmdletBinding()]
5+
param (
6+
[Parameter(Position = 0)]
7+
[Switch] $Silent
8+
)
9+
10+
$CleanOptions = @(
11+
"Active Setup Temp Folders"
12+
"BranchCache"
13+
"D3D Shader Cache"
14+
"Delivery Optimization Files"
15+
"Diagnostic Data Viewer database files"
16+
"Downloaded Program Files"
17+
"Feedback Hub Archive log files"
18+
"Internet Cache Files"
19+
"Language Pack"
20+
"Old ChkDsk Files"
21+
"Recycle Bin"
22+
"RetailDemo Offline Content"
23+
"Setup Log Files"
24+
"System error memory dump files"
25+
"System error minidump files"
26+
"Temporary Files"
27+
"Temporary Setup Files"
28+
"Thumbnail Cache"
29+
"Update Cleanup"
30+
"User file versions"
31+
"Windows Defender"
32+
"Windows Error Reporting Files"
33+
"Windows Upgrade Log Files"
34+
)
35+
$PathToLMCleangmrSettings = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
36+
$TweakType = "Disk"
37+
38+
Write-Status -Types "+", $TweakType -Status "Cleaning the $env:SystemRoot\WinSxS folder..."
39+
DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase | Out-Host
40+
41+
Write-Status -Types "+", $TweakType -Status "Cleaning up more system folders..."
42+
If (!$Silent) {
43+
Start-Process cleanmgr.exe -ArgumentList "/d $env:SystemDrive", "/VERYLOWDISK" -Wait
44+
} Else {
45+
ForEach ($Key in $CleanOptions) {
46+
Set-ItemPropertyVerified -Path "$PathToLMCleangmrSettings\$Key" -Name "StateFlags0777" -Type DWord -Value 2
47+
}
48+
49+
Start-Process cleanmgr.exe -ArgumentList "/d $env:SystemDrive", "/SAGERUN:777" -Wait
50+
}
51+
}
52+
53+
Start-DiskCleanUp -Silent

0 commit comments

Comments
 (0)