‘New’ Item Cleaner

Introduction

The ‘New >‘ item on the right-click menu is quite handy.  It can list a huge amount of document types for you to create new documents.  Most of the time these work, other times they don’t.

 

Problem

As this list grows when new applications are installed, it rarely shrinks when an application is removed.  This can lead to dead links.

Another issue with this list is custom desktops for Citrix XenApp users, or other users on locked down, permissions based terminal servers.  There may be links in the list that a particular user doesn’t have access to.

nic-1

Solution

One solution is to just ignore it.  Users may log tickets sayinIg they can’t access an application they are not allowed to have, causing you to waste time and effort on chasing your tails.

While I was working with a particular Citrix XenApp install quite a few years ago, I created a script in KIX that would remove the entire list of applications, except for “Text Document”  I have recently updated this script for PowerShell and thought that I would share it with you.

nic-2

 As you can see from the screen shots, all the new document links have gone except for the only one we want.

 

The Script

The script is listed below…

Push-Location
Set-Location 'REGISTRY::HKEY_CLASSES_ROOT'
# Get all keys under the root branch...
$RegKeyItems = Get-ChildItem
ForEach ($RegKey in $RegKeyItems)
{
    # Check if it starts with a full stop "."
    If ($RegKey.PSChildName.StartsWith('.'))
    {
        # Get all keys under current branch...
        $RegSubKeyItems = Get-ChildItem -Path $RegKey.PSChildName
        ForEach ($RegSubKey in $RegSubKeyItems)
        {
            # Looking for "ShellNew"...
            If ($RegSubKey.PSChildName -eq 'ShellNew')
            {
                # Make sure not to remove Shortcut Links or Text Documents
                If (($RegKey.PSChildName -ne '.lnk') -and ($RegKey.PSChildName -ne '.txt'))
                {
                    # Display and delete key...
                    write-host "Deleting: $RegSubKey"
                    Remove-Item -Path \$RegSubKey -Recurse -ErrorAction SilentlyContinue
                }
                # Same as above, checking one level deeper...
                $RegSubSubKeyItems = Get-ChildItem -Path $RegSubKey.PSChildName -ErrorAction SilentlyContinue
                ForEach ($RegSubSubKey in $RegSubSubKeyItems)
                {
                    # Looking for "ShellNew"...
                    If ($RegSubSubKey.PSChildName -eq 'ShellNew')
                    {
                        # Make sure not to remove Shortcut Links or Text Documents
                        If (($RegSubKey.PSChildName -ne '.lnk') -and ($RegSubKey.PSChildName -ne '.txt'))
                        {
                            # Display and delete key...
                            write-host "Deleting: $RegSubSubKey"
                            Remove-Item -Path \$RegSubSubKey -Recurse -ErrorAction SilentlyContinue
                        }
                    }
                }
            }
        }
    }
}
# Also remove that annoying Briefcase link...
Remove-Item -Path '\Briefcase\ShellNew' -Recurse -ErrorAction SilentlyContinue
Pop-Location

 

If you have any suggestions for improvements, or want to share your tweaks, leave a comment below.

 

Download

download-fileNew Item Cleaner.ps1

 

Leave a Reply

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