diff --git a/WindowsCleaner.exe b/WindowsCleaner.exe index 9936bd0..282c0b6 100644 Binary files a/WindowsCleaner.exe and b/WindowsCleaner.exe differ diff --git a/WindowsCleaner.ps1 b/WindowsCleaner.ps1 index 297e375..1e2b979 100644 --- a/WindowsCleaner.ps1 +++ b/WindowsCleaner.ps1 @@ -5,7 +5,7 @@ if ($WindowsVersion -ne "2009") { break } -Write-Host -ForegroundColor Yellow "ATTENTION : Ce script va supprimer les téléchargements de plus de 30 jours pour TOUS LES UTILISATEURS !" +Write-Host -ForegroundColor DarkYellow "ATTENTION : Ce script va supprimer les téléchargements de plus de 30 jours pour TOUS LES UTILISATEURS !" $Confirm = Read-Host "Êtes-vous sûr(e) de vouloir continuer ? (tapez OUI si vous souhaitez continuer)" if ($Confirm -eq "OUI") { @@ -14,7 +14,7 @@ if ($Confirm -eq "OUI") $delai = 30 $limit = (Get-Date).AddDays(-$delai) $users = get-childitem c:\users - Write-Host "Nettoyage..." + Write-Host -ForegroundColor DarkYellow "Nettoyage..." foreach ($user in $users) { Get-ChildItem -Path C:\Users\$user\Downloads\* -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force -Erroraction silentlycontinue @@ -26,7 +26,7 @@ if ($Confirm -eq "OUI") Write-Host "II. Nettoyage des caches des navigateurs Google Chrome, Mozilla Firefox et Internet Explorer pour tous les utilisateurs" dir C:\Users | select Name | Export-Csv -Path C:\users\$env:USERNAME\users.csv -NoTypeInformation $list=Test-Path C:\users\$env:USERNAME\users.csv - Write-Host -ForegroundColor Yellow "Nettoyage des caches Firefox..." + Write-Host -ForegroundColor DarkYellow "Nettoyage des caches Firefox..." Write-Host -ForegroundColor cyan Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach { Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\* -Recurse -Force -EA SilentlyContinue @@ -38,7 +38,7 @@ if ($Confirm -eq "OUI") Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\chromeappsstore.sqlite -Recurse -Force -EA SilentlyContinue } Write-Host -ForegroundColor Green "Nettoyage des caches Firefox terminé !" - Write-Host -ForegroundColor Yellow "Nettoyage des caches Chrome..." + Write-Host -ForegroundColor DarkYellow "Nettoyage des caches Chrome..." Write-Host -ForegroundColor cyan Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach { Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue @@ -52,7 +52,7 @@ if ($Confirm -eq "OUI") Write-Host -ForegroundColor Green "Nettoyage des caches Chrome terminé !" # Clear Internet Explorer - Write-Host -ForegroundColor Yellow "Nettoyage des caches Internet Explorer..." + Write-Host -ForegroundColor DarkYellow "Nettoyage des caches Internet Explorer..." Write-Host -ForegroundColor cyan Import-CSV -Path C:\users\$env:USERNAME\users.csv | foreach { Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -EA SilentlyContinue @@ -67,18 +67,43 @@ if ($Confirm -eq "OUI") Write-Host -ForegroundColor Green "Nettoyage des caches navigateurs terminé !" sleep 2 Write-Host "III. Nettoyage du cache Windows Update..." - Write-Host "Arrêt de Windows Update..." + Write-Host -ForegroundColor DarkYellow "Arrêt de Windows Update..." net stop wuauserv - Write-Host "Vidage du cache Windows Update..." + Write-Host -ForegroundColor DarkYellow "Vidage du cache Windows Update..." Remove-Item C:\Windows\SoftwareDistribution\Download\*.* -Recurse -Force - Write-Host "Démarrage de Windows Update..." + Write-Host -ForegroundColor DarkYellow "Démarrage de Windows Update..." net start wuauserv Write-Host -ForegroundColor Green "Nettoyage du cache Windows Update terminé !" + + Write-Host "IV. Nettoyage du noyau Windows" + Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase + Write-Host -ForegroundColor Green "Nettoyage du noyau Windows terminé !" + + Write-Host "V. Nettoyage de disque façon Microsoft" + Write-Host -ForegroundColor DarkYellow 'Nettoyage des paramètres automatiques de CleanMgr...' + Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*' -Name StateFlags0001 -ErrorAction SilentlyContinue | Remove-ItemProperty -Name StateFlags0001 -ErrorAction SilentlyContinue + + Write-Host -ForegroundColor DarkYellow 'Activation du nettoyage Windows Update...' + New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup' -Name StateFlags0001 -Value 2 -PropertyType DWord + + Write-Host -ForegroundColor DarkYellow 'Activation du nettoyage des fichiers temporaires' + New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files' -Name StateFlags0001 -Value 2 -PropertyType DWord + + Write-Host -ForegroundColor DarkYellow 'Lancement du nettoyage...' + Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -WindowStyle Hidden -Wait + + Write-Host -ForegroundColor DarkYellow 'Nettoyage en cours...' + Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process + + Write-Host -ForeGroundColor Green 'Nettoyage de disque terminé !' + Write-Host -ForegroundColor Green "Nettoyage de Windows terminé." + $TailleApres = ([math]::Round((get-PSDrive C).Free/1GB,2)) $EspaceGagne = $TailleApres - $TailleAvant $EspaceGagneRound = [math]::Round($EspaceGagne,2) - Write-Host "Ce nettoyage a permis de récupérer $EspaceGagneRound Go !" + + Write-Host -ForegroundColor DarkYellow "Ce nettoyage a permis de récupérer $EspaceGagneRound Go !" pause } else{