Did you ever wonder how to get rid of those orphaned Citrix Start Menu Shortcuts and/or folders?
Well, wonder no more! Here is the script (Remove-CitrixShortcuts.ps1) to remove any Citrix-related shortcut (lnk file extension) from selected Paths.
Simply adjust the Paths variable to your requiremets.
#############################################################################
# Script: Remove-CitrixShortcutsps1
# Author: Alexander Ollischer
# Blog: https://blog.ollischer.com
# Date: 12/14/2015
# Keywords: Citrix Shortcuts, Orphaned Shortcuts, Folders, Empty, Directories, Containers
#############################################################################
# DISCLAIMER
#############################################################################
# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#############################################################################
Clear-Host
$Paths = "$env:APPDATA\Microsoft\Windows\Start Menu\","$home\Desktop\","$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
#Add some logging...
$LogTime = Get-Date -Format "mm-dd-yyyy_hh-mm-ss"
$LogFile = "$home\Remove-CitrixShortcuts_"+$LogTime+".log"
$wshShell = New-Object -ComObject WScript.Shell
ForEach($Path in $Paths) {
$Files = Get-ChildItem $Path -Recurse -Include *.lnk
foreach ($file in $Files) {
$shortcut = $wshShell.CreateShortcut($file.FullName)
if ($shortcut.TargetPath -like "*Citrix*") {
$shortcut.TargetPath | Out-File $LogFile -Append
$file.FullName | Out-File $LogFile -Append
Remove-Item $file
#Remove-Item $file -WhatIf
}
}
}
After that there maybe some empty folders left that need removing, too. Use this script (Remove-EmptyFolders.ps1) after removing the shortcuts in order to remove them as well (courtesy of Chris Brown, who pointed me in the right direction):
$Paths = "$env:APPDATA\Microsoft\Windows\Start Menu\","$home\Desktop\"
#Add some logging...
$LogTime = Get-Date -Format "mm-dd-yyyy_hh-mm-ss"
$LogFile = "$home\Remove-EmptyFolders_"+$LogTime+".log"
# Get each item under the current directory recursively
# enhanced filter by Empty Folders and Verify through File Count
foreach($childItem in (Get-ChildItem $Paths -Recurse | Where-Object {$_.PSIsContainer -eq $True} | Where-Object {$_.GetFiles().Count -eq 0}))
{
# if it's a folder AND does not have child items of its own
if( ($childItem.PSIsContainer) -and (!(Get-ChildItem -Recurse -Path $childItem.FullName)))
{
# Delete it
$childItem.FullName | Out-File $LogFile -Append
Remove-Item $childItem.FullName -Confirm:$false
}
}
Both scripts can be downloaded here: