Skip to content

Commit

Permalink
feat: revise cleanup.ps1 script
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyueta committed Oct 18, 2023
1 parent f0e6559 commit 8c38bd0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 54 deletions.
1 change: 0 additions & 1 deletion src/playbook/Configuration/tweaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ features:
# -------------------------------------------------------------------------- #
- tweaks\performance\system\config-boot-config.yml
- tweaks\performance\system\config-paging.yml
- tweaks\performance\system\disable-reserved-storage.yml
- tweaks\performance\system\optimize-ntfs.yml
- tweaks\performance\system\service-host-split.yml
- tweaks\performance\system\win32-priority-seperation.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ actions:
- !registryValue: {path: 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy', value: '256', type: REG_DWORD, data: '30'}

# Enable cleaning temp files
- !run:
exe: 'schtasks.exe'
args: '/change /tn "Microsoft\Windows\DiskCleanup\SilentCleanup" /enable'
wait: true
- !scheduledTask: {path: '\Microsoft\Windows\DiskCleanup\SilentCleanup', operation: enable}

# There's also subkeys for OneDrive cleanup, but as OneDrive is uninstalled, they probably aren't relevant
68 changes: 34 additions & 34 deletions src/playbook/Configuration/tweaks/debloat/scheduled-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ actions:
path: '\Microsoft\Windows\Location'
operation: deleteFolder

- !scheduledTask: {path: '\Microsoft\Windows\Application Experience\PcaPatchDbTask', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Application Experience\StartupAppTask', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\DsSvcCleanup', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\CloudExperienceHost\CreateObjectTask', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Diagnosis\Scheduled', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\DiskFootprint\Diagnostics', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\InstallService\ScanForUpdates', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\InstallService\ScanForUpdatesAsUser', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\PI\Sqm-Tasks', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Registry\RegIdleBackup', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\FamilySafetyMonitor', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\FamilySafetyRefresh', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\IndexerAutomaticMaintenance', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\StateRepository\MaintenanceTasks', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\WindowsUpdate\Scheduled Start', operation: delete}
- !scheduledTask: {path: '\Microsoft\Windows\Application Experience\PcaPatchDbTask'}
- !scheduledTask: {path: '\Microsoft\Windows\Application Experience\StartupAppTask'}
- !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\DsSvcCleanup'}
- !scheduledTask: {path: '\Microsoft\Windows\CloudExperienceHost\CreateObjectTask'}
- !scheduledTask: {path: '\Microsoft\Windows\Diagnosis\Scheduled'}
- !scheduledTask: {path: '\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector'}
- !scheduledTask: {path: '\Microsoft\Windows\DiskFootprint\Diagnostics'}
- !scheduledTask: {path: '\Microsoft\Windows\InstallService\ScanForUpdates'}
- !scheduledTask: {path: '\Microsoft\Windows\InstallService\ScanForUpdatesAsUser'}
- !scheduledTask: {path: '\Microsoft\Windows\PI\Sqm-Tasks'}
- !scheduledTask: {path: '\Microsoft\Windows\Registry\RegIdleBackup'}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\FamilySafetyMonitor'}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\FamilySafetyRefresh'}
- !scheduledTask: {path: '\Microsoft\Windows\Shell\IndexerAutomaticMaintenance'}
- !scheduledTask: {path: '\Microsoft\Windows\StateRepository\MaintenanceTasks'}
- !scheduledTask: {path: '\Microsoft\Windows\WindowsUpdate\Scheduled Start'}

# Here are the scheduled tasks that are currently commented as they're under review.
# This list should be somewhat minimal in the tasks it deletes, as a lot of the tasks below won't run by default ever anyways, unless needed.
Expand All @@ -34,21 +34,21 @@ actions:
# path: '\Microsoft\Windows\DeviceDirectoryClient'
# operation: deleteFolder

# - !scheduledTask: {path: '\Microsoft\Windows\AppID\EDP Policy Manager', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\appuriverifierdaily', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\appuriverifierinstall', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\BrokerInfrastructure\BgTaskRegistrationMaintenanceTask', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Defrag\ScheduledDefrag', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Device Setup\Metadata Refresh', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\InstallService\SmartRetry', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Maintenance\WinSAT', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Management\Provisioning\Cellular', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\MemoryDiagnostic\ProcessMemoryDiagnosticEvents', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\MemoryDiagnostic\RunFullMemoryDiagnostic', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Printing\EduPrintProv', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\PushToInstall\LoginCheck', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Ras\MobilityManager', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\UPnP\UPnPHostConfig', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\WaaSMedic\PerformRemediation', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\Windows Media Sharing\UpdateLibrary', operation: delete}
# - !scheduledTask: {path: '\Microsoft\Windows\AppID\EDP Policy Manager'}
# - !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\appuriverifierdaily'}
# - !scheduledTask: {path: '\Microsoft\Windows\ApplicationData\appuriverifierinstall'}
# - !scheduledTask: {path: '\Microsoft\Windows\BrokerInfrastructure\BgTaskRegistrationMaintenanceTask'}
# - !scheduledTask: {path: '\Microsoft\Windows\Defrag\ScheduledDefrag'}
# - !scheduledTask: {path: '\Microsoft\Windows\Device Setup\Metadata Refresh'}
# - !scheduledTask: {path: '\Microsoft\Windows\InstallService\SmartRetry'}
# - !scheduledTask: {path: '\Microsoft\Windows\Maintenance\WinSAT'}
# - !scheduledTask: {path: '\Microsoft\Windows\Management\Provisioning\Cellular'}
# - !scheduledTask: {path: '\Microsoft\Windows\MemoryDiagnostic\ProcessMemoryDiagnosticEvents'}
# - !scheduledTask: {path: '\Microsoft\Windows\MemoryDiagnostic\RunFullMemoryDiagnostic'}
# - !scheduledTask: {path: '\Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem'}
# - !scheduledTask: {path: '\Microsoft\Windows\Printing\EduPrintProv'}
# - !scheduledTask: {path: '\Microsoft\Windows\PushToInstall\LoginCheck'}
# - !scheduledTask: {path: '\Microsoft\Windows\Ras\MobilityManager'}
# - !scheduledTask: {path: '\Microsoft\Windows\UPnP\UPnPHostConfig'}
# - !scheduledTask: {path: '\Microsoft\Windows\WaaSMedic\PerformRemediation'}
# - !scheduledTask: {path: '\Microsoft\Windows\Windows Media Sharing\UpdateLibrary'}

This file was deleted.

54 changes: 45 additions & 9 deletions src/playbook/Executables/CLEANUP.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# Clearing the user's temporary folder
Get-ChildItem -Path "$env:TEMP" -File | Remove-Item -Force -EA SilentlyContinue

# Clearing the Windows Temp folder
Remove-Item -Path '$env:windir\Temp\*' -Force -Recurse -EA SilentlyContinue

# Exclude the AME folder while deleting directories in the temporary folder
Get-ChildItem -Path "$env:TEMP" -Directory | Where-Object { $_.Name -ne 'AME' } | Remove-Item -Force -Recurse -EA SilentlyContinue
# AtlasOS Post-Installation Cleanup Utility

# As cleanmgr has multiple processes, there's no point in making the window hidden as it won't apply
function Invoke-AtlasDiskCleanup {
Expand Down Expand Up @@ -59,4 +52,47 @@ foreach ($drive in $drives) {
}
}

if (!($otherInstalls)) { Invoke-AtlasDiskCleanup }
if (!($otherInstalls)) { Invoke-AtlasDiskCleanup }

# Clear the temporary user folder
Get-ChildItem -Path "$env:TEMP" -File | Remove-Item -Force -EA SilentlyContinue

# Exclude the AME folder while deleting directories in the temporary user folder
Get-ChildItem -Path "$env:TEMP" -Directory | Where-Object { $_.Name -ne 'AME' } | Remove-Item -Force -Recurse -EA SilentlyContinue

# Clear the temporary system folder
Remove-Item -Path "$env:windir\Temp\*" -Force -Recurse -EA SilentlyContinue

# Disable Reserved Storage to have more storage space
Set-WindowsReservedStorageState -State Disabled

# Clear Windows WinSxS folder
DISM /Online /Cleanup-Image /StartComponentCleanup

# Clear Event Logs
wevtutil el 2>$null | ForEach-Object {wevtutil cl "$_"} 2>$null

# Remove any .log files
Get-ChildItem -Path "$env:SystemRoot" -Filter *.log -File -Recurse -Force 2>$null | Remove-Item -Recurse -Force 2>$null

Stop-Service -Name "dps" -Force
Stop-Service -Name "wuauserv" -Force
Stop-Service -Name "cryptsvc" -Force

# Clean up leftovers
$foldersToRemove = @(
"CbsTemp",
"Logs",
"SoftwareDistribution",
"System32\catroot2"
"System32\LogFiles",
"System32\sru",
"WinSxS\Backup"
)

foreach ($folderName in $foldersToRemove) {
$folderPath = Join-Path $env:SystemRoot $folderName
if (Test-Path $folderPath) {
Remove-Item -Path "$folderPath\*" -Force -Recurse -Verbose
}
}

0 comments on commit 8c38bd0

Please sign in to comment.