How to rebuild icon cache in Windows 8.1 (PowerShell)

Introduction

This PowerShell Script shows how to rebuild icon cache in Windows 8.1.

Scenarios

Sometimes users encounter the issues that an icon is changed to a different random icon, several icons are drawn on top of each other or an icon becomes all black and so on. This script will help users to fix that.

Script

Step1: To run the script in the Windows PowerShell Console, type the command< Script Path> at the Windows PowerShell Console.

For example, type C:\Script\RebuildIconCache\RebuildIconCache.ps1

The step is shown in the following figure.

When the script finishes running, Windows PowerShell Console displays brief information about the script.

Here are some code snippets for your reference.

- PowerShell code snippet -
 
Try
{
    #Check if file exists
    If(Test-Path -Path "$env:LOCALAPPDATA\IconCache.db")
    {
        Remove-Item -Path "$env:LOCALAPPDATA\IconCache.db" -Force
    }
    #Restart process
    Start-Process $ProcessName
 
    Invoke-Expression -Command "ie4uinit.exe -cleariconcache"
    Write-Host "Successfully refreshed icon cache."
}
Catch
{
    Write-Warning "Failed to refreshed icon cache."
}
 
- end -

 

Prerequisite

Windows PowerShell 3.0

Windows 8.1