Delete invalid shortcut on the Start screen in Windows 8 (PowerShell)

Introduction

This PowerShell script shows how to remove invalid shortcut on the Start menu.

Scenarios

Sometimes when you uninstall software on your computer, even though the software is uninstalled successfully, it leaves some shortcuts that were created behind in your computer. These shortcuts do not work as the main software is uninstalled. Perhaps you move a file or a folder to a different location, the shortcut to that file or folder becomes invalid as it still points to the earlier location.

Script

Step1: Run the script in the Windows PowerShell Console, type the one command: <Script Path> at the prompt.For example, type C:\Script\ emoveInvaildShortcutInStartScreen.ps1
The step is shown in the following figure.

As you can see, there is a shortcut file in the Start screen called Document. Actually, the shortcut file was invalid.

We can use the script to remove invalid shortcut file. When the script finishes running, Windows PowerShell Console displays brief information about the script.

The result is shown below:

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page. 

PowerShell
Edit|Remove
Foreach ($LnkFilein$AllLnkFiles) 
{ 
    #Gets target path of shortcut $LnkFilePath = $LnkFile.FullName 
    $LnkShortcut = $WshShell.CreateShortcut($LnkFilePath) 
    $LnkTargetPath = $LnkShortcut.TargetPath 
  
    If (Test-Path-Path $LnkTargetPath) 
    { 
        Write-Host "The ""$($LnkFile.BaseName)"" shortcut file is still vaild." 
    } 
    Else 
    { 
        Remove-Item-Path $LnkFilePath 
        Write-Host "The ""$($LnkFile.BaseName)"" shortcut file was successfully removed from Start screen."-ForegroundColor Green 
    } 
}

Prerequisite

Windows PowerShell 3.0

Windows 8

Additional Resources

New-Object