Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Search Icon Cache / Thumbnail Rebuild
# Run a quick purge of search cache, as well icon and thumbnail cache on your computer.
# v1.2.0
# === Learn More ===
# While this script is clearly safe, Windows may block this file. You will need to unblock it if that's the case.
# Additionally, PowerShell blocks scripts for safety. Run the command: set-executionpolicy unrestricted
# You can revert this change with the command: set-executionpolicy restricted
# Copy and paste into an empty notepad window. Save it as "what_ever_you_want_to_name_it.ps1".
# This will bypass the need to change execution policy and unblock files.
# Right click this file and select "Run with PowerShell"
# BEGIN SCRIPT ============================================================================================================================
# need admin rights
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
# warning messsage
write-host "Please close ALL open programs and services!" -foregroundcolor Red
write-host "After this process completes, you computer will be rebooted." -foregroundcolor Red
# End these so system icon cache can be deleted.
Stop-Service -Name WSearch
Set-Service -StartupType Disabled WSearch
taskkill /f /im explorer.exe
taskkill /f /im RuntimeBroker.exe
taskkill /f /im dllhost.exe
taskkill /f /im taskmgr.exe
# Delete the icon and thumb cache.
remove-item "$env:localappdata\Microsoft\Windows\Explorer" -recurse -force
# This line isn't needed. This file is created by Explorer and only exists while it runs.
#remove-item "$env:localappdata\IconCache.db" -force
# delete search data.
remove-item "C:\ProgramData\Microsoft\Search" -recurse -force
# End these and clean up.
taskkill /f /im SearchApp.exe
remove-item "$env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy" -recurse -force
taskkill /f /im StartMenuExperienceHost.exe # It's normally already killed when you kill explorer. Here just in case.
remove-item "$env:localappdata\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy" -recurse -force
remove-item "$env:localappdata\Packages\windows.immersivecontrolpanel_cw5n1h2txyewy" -recurse -force
# Enable and start Windows Search
Set-Service -StartupType Automatic WSearch
Start-Service -Name WSearch
start-sleep 2
# reboot
shutdown /r /t 0
# ========================================
# stuff used during initial testing.
# logout current user
# misc options for starting explorer again.
#$Executor = whoami
#Start-Process explorer.exe -Credential "$Executor"
#Start-Process taskmgr.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment