Print
Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

I’m a rather geeky type person with a passion for clean desktops. My physical desktop is always pretty clean and I like my computer desktops to be clean, too. I don’t like anything on my desktop, including icons, especially on Windows 8.1, Server 2012 R2, and later, with their Start screen and taskbar. (I make an exception for the Recycle Bin, which really isn’t an icon.) But habits die hard and some people like icons, so they’re still popular.

Automating the removal of icons from Windows 7 and earlier versions of Windows is particularly difficult. Most programs add their desktop icons to the All Users or Public desktop. To use Windows PowerShell to delete icons from desktops on Windows 7 and earlier, you need to take ownership of the All Users directory. That hardship seems to have been eliminated on Windows 8.1.

To remove all icons from all Windows 8.1 desktops on a single computer:

  1. Start Windows PowerShell (or PowerShell Studio) with the Run as administrator option.
  2. Run this command:
Remove-Item C:\Users\*\Desktop\*lnk –Force

The Force parameter is required on Windows 8.1 Pro and it doesn’t do any harm on other systems.

To remove all icons from a collection of local and remote computers in a Servers.txt file.

Invoke-Command -ComputerName (Get-Content Servers.txt) `
    -ScriptBlock { Remove-Item C:\Users\*\Desktop\*lnk -Force }

If you run this command frequently, create a function for it and add it to your Windows PowerShell profile. I also add a warning that reminds me when I’m not running as an administrator. The cool isAdmin function is one of several versions of this function. This one was developed by Windows PowerShell MVP Shay Levy.

Finally, because I’m deleting something, I add the SupportsShouldProcess parameter of the CmdletBinding attribute and I make that link path a parameter (-Path), in case a user prefers to remove icons in only one user desktop.

 

#PowerShell MVP Shay Levy (@ShayLevy on Twitter)
function isAdmin
{
([
Security.Principal.WindowsPrincipal] `
[
Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole]“Administrator”)
}

 

function Remove-Icons
{
    [CmdletBinding(SupportsShouldProcess = $true)]
    param
    (
        [string]
        $Path = "C:\Users\*\Desktop\*lnk"
    )
    if (!(IsAdmin))
    {
        Write-Warning "To remove icons from all desktops, start 
                       Windows PowerShell with the 'Run as administrator' option."
    }
    
    if ($pscmdlet.ShouldProcess($path))
    {
        Remove-Item $Path -Force
    }
}

 

Hope this helps to keep your desktop clean.

June Blender is a technology evangelist at SAPIEN Technologies, Inc. You can reach her at This email address is being protected from spambots. You need JavaScript enabled to view it. or follow her on Twitter at @juneb_get_help.

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.