Write-Host "Le Nettoyage de votre poste est en cours, veuillez patienter cela peut prendre un moment" -Foreground Yellow
Remove-Item "C:\WINDOWS\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Suppression du contenu du dossier Temp de la partition système OK" -ForegroundColor Green
Remove-Item "C:\Users\*\Appdata\Local\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Suppression des dossiers Temp des profils utilisateurs OK" -ForegroundColor Green
Clear-RecycleBin -Force
Write-Host "Suppression du contenu de la corbeille de tous les utilisateurs OK" -ForegroundColor Green
#Utilisation de CleanMGR
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files' -Name StateFlags0100 -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
Write-Host "Démarrage de CleanMGR.exe..."
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:100' -WindowStyle Hidden -Wait
Write-Host "En attente du traitement de CleanMGR.exe... Veuillez patienter."
Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process
Write-Host "Suppression des fichiers des anciennes versions de Windows..."
cleanmgr.exe /AUTOCLEAN /d C:
Write-Host "Le nettoyage de l'hôte est terminé." -ForegroundColor Green
# Lancement en remote
$cred = Get-Credential "domain\administrator";
Invoke-Command -ComputerName "computer004" {
Process {
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*' | % {
New-ItemProperty -Path $_.PSPath -Name StateFlags0001 -Value 2 -PropertyType DWord -Force
};
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -WindowStyle Hidden
}
} -AsJob -Credential $cred