Skip to content

Commit c593b83

Browse files
authored
Refactor CLEANER.ps1 script
1 parent 582eaa9 commit c593b83

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Executables/CLEANER.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
$ErrorActionPreference = 'SilentlyContinue'
12

23
Write-Host "Using Disk Cleanup with custom configuration"
34
$volumeCache = @{
@@ -31,15 +32,15 @@ $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Volume
3132
foreach ($item in $volumeCache.GetEnumerator()) {
3233
$keyPath = Join-Path $registryPath $item.Key
3334
if (Test-Path $keyPath) {
34-
Write-Host "Cleaning up $item.Key"
35+
3536
New-ItemProperty -Path $keyPath -Name StateFlags1337 -Value $item.Value -PropertyType DWord | Out-Null
3637
}
3738
}
3839

3940
Start-Process -FilePath "$env:SystemRoot\system32\cleanmgr.exe" -ArgumentList "/sagerun:1337" -Wait:$false
4041

4142
Write-Host "Cleaning up Event Logs"
42-
Get-EventLog -LogName * | ForEach { Clear-EventLog $_.Log }
43+
Get-EventLog -LogName * | ForEach-Object { Clear-EventLog $_.Log }
4344

4445
Write-Host "Disabling Reserved Storage"
4546
Set-WindowsReservedStorageState -State Disabled
@@ -66,7 +67,7 @@ $foldersToRemove = @(
6667
foreach ($folderName in $foldersToRemove) {
6768
$folderPath = Join-Path $env:SystemRoot $folderName
6869
if (Test-Path $folderPath) {
69-
Remove-Item -Path "$folderPath\*" -Force -Recurse -ErrorAction SilentlyContinue | Out-Null
70+
Remove-Item -Path "$folderPath\*" -Force -Recurse | Out-Null
7071
}
7172
}
7273

@@ -75,7 +76,7 @@ foreach ($folderName in $foldersToRemove) {
7576
Get-ChildItem -Path "$env:SystemRoot" -Filter *.log -File -Recurse -Force | Remove-Item -Recurse -Force | Out-Null
7677

7778
Write-Host "Cleaning up %TEMP%"
78-
Get-ChildItem -Path "$env:TEMP" -Exclude "AME" | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
79+
Get-ChildItem -Path "$env:TEMP" -Exclude "AME" | Remove-Item -Recurse -Force
7980

8081
# Just in case
8182
Start-ScheduledTask -TaskPath "\Microsoft\Windows\DiskCleanup\" -TaskName "SilentCleanup"

0 commit comments

Comments
 (0)