1
+ $ErrorActionPreference = ' SilentlyContinue'
1
2
2
3
Write-Host " Using Disk Cleanup with custom configuration"
3
4
$volumeCache = @ {
@@ -31,15 +32,15 @@ $registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Volume
31
32
foreach ($item in $volumeCache.GetEnumerator ()) {
32
33
$keyPath = Join-Path $registryPath $item.Key
33
34
if (Test-Path $keyPath ) {
34
- Write-Host " Cleaning up $item .Key "
35
+
35
36
New-ItemProperty - Path $keyPath - Name StateFlags1337 - Value $item.Value - PropertyType DWord | Out-Null
36
37
}
37
38
}
38
39
39
40
Start-Process - FilePath " $env: SystemRoot \system32\cleanmgr.exe" - ArgumentList " /sagerun:1337" - Wait:$false
40
41
41
42
Write-Host " Cleaning up Event Logs"
42
- Get-EventLog - LogName * | ForEach { Clear-EventLog $_.Log }
43
+ Get-EventLog - LogName * | ForEach-Object { Clear-EventLog $_.Log }
43
44
44
45
Write-Host " Disabling Reserved Storage"
45
46
Set-WindowsReservedStorageState - State Disabled
@@ -66,7 +67,7 @@ $foldersToRemove = @(
66
67
foreach ($folderName in $foldersToRemove ) {
67
68
$folderPath = Join-Path $env: SystemRoot $folderName
68
69
if (Test-Path $folderPath ) {
69
- Remove-Item - Path " $folderPath \*" - Force - Recurse - ErrorAction SilentlyContinue | Out-Null
70
+ Remove-Item - Path " $folderPath \*" - Force - Recurse | Out-Null
70
71
}
71
72
}
72
73
@@ -75,7 +76,7 @@ foreach ($folderName in $foldersToRemove) {
75
76
Get-ChildItem - Path " $env: SystemRoot " - Filter * .log - File - Recurse - Force | Remove-Item - Recurse - Force | Out-Null
76
77
77
78
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
79
80
80
81
# Just in case
81
82
Start-ScheduledTask - TaskPath " \Microsoft\Windows\DiskCleanup\" - TaskName " SilentCleanup"
0 commit comments