Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created March 28, 2020 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pknowledge/3e56ecab7eccc1e425893de0fb6def30 to your computer and use it in GitHub Desktop.
Save pknowledge/3e56ecab7eccc1e425893de0fb6def30 to your computer and use it in GitHub Desktop.
Clean PC using powershell
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace(0xA)
$WinTemp = "c:\Windows\Temp\*"
#1# Empty Recycle Bin #
write-Host "Emptying Recycle Bin." -ForegroundColor Cyan
$objFolder.items() | %{ remove-item $_.path -Recurse -Confirm:$false}
#2# Remove Temp
write-Host "Removing Temp" -ForegroundColor Green
Set-Location “C:\Windows\Temp”
Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue
Set-Location “C:\Windows\Prefetch”
Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue
Set-Location “C:\Documents and Settings”
Remove-Item “.\*\Local Settings\temp\*” -Recurse -Force -ErrorAction SilentlyContinue
Set-Location “C:\Users”
Remove-Item “.\*\Appdata\Local\Temp\*” -Recurse -Force -ErrorAction SilentlyContinue
#3# Running Disk Clean up Tool
write-Host "Finally now , Running Windows disk Clean up Tool" -ForegroundColor Cyan
cleanmgr /sagerun:1 | out-Null
$([char]7)
Sleep 3
write-Host "I finished the cleanup task,Bye Bye " -ForegroundColor Yellow
Sleep 3
##### End of the Script #####
@dhanushraju
Copy link

came from programming knowledge yt channel

@rd842003
Copy link

rd842003 commented Sep 3, 2021

This caused me not to be able to log back into my windows account. I keep getting device offline error

@c4coer
Copy link

c4coer commented Jun 25, 2023

effectivement la commande
Remove-Item “.*\Local Settings\temp*” -Recurse -Force -ErrorAction SilentlyContinue

Set-Location “C:\Users”
Remove-Item “.\*\Appdata\Local\Temp\*” -Recurse -Force -ErrorAction SilentlyContinue

supprime le profil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment