Remove Desktop items with PowerShell

16. April 2015

If you want to remove Desktop items with PowerShell, this script will get the local Desktop folder from the registry and look for the item mentioned in line 5 to remove it (old shortcuts for example).

$desktopfolder = (Get-ItemProperty "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders").Desktop
$shortcuts = Get-Childitem $desktopfolder
foreach ($item in $shortcuts)
    {
        if ($item -match "example.lnk")
        { 
        Remove-Item $item.fullname
        echo "#########################################################################"
        echo $date 
        echo "$item from User $env:USERNAME at $env:COMPUTERNAME in $desktopfolder removed."
        }
    }

PowerShell Version: 4
Modules: none

#PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *


*