Skip to content

Instantly share code, notes, and snippets.

@figueroadavid
Created February 1, 2024 12:58
Show Gist options
  • Select an option

  • Save figueroadavid/c03f4189b224dc2a50039fa9b0b9f5e7 to your computer and use it in GitHub Desktop.

Select an option

Save figueroadavid/c03f4189b224dc2a50039fa9b0b9f5e7 to your computer and use it in GitHub Desktop.
Deletes any desktop shortcuts generated by Citrix Workspace App
function Clear-CitrixDesktopShortcuts {
<#
.SYNOPSIS
Deletes desktop shortcuts that are generated by Citrix Workspace App/Receiver
.DESCRIPTION
The script retrieves all of the shortcuts from the user's desktop folder and checks
each of the .lnk files for a target path that matches 'AppData\Roaming\Citrix\SelfService'.
If the link file matches, the file is deleted.
.NOTES
This uses the wscript.shell object, and the script does release all of the COM objects to prevent memory leaks.
.EXAMPLE
PS C:\>Clear-CitrixDesktopShortcuts -Verbose
VERBOSE: Deleting Citrix shortcut: EXCEL
VERBOSE: Deleting Citrix shortcut: OUTLOOK
VERBOSE: Deleting Citrix shortcut: Project
VERBOSE: Deleting Citrix shortcut: Visio
VERBOSE: Deleting Citrix shortcut: Word
#>
[cmdletbinding()]
param()
$WSHShell = New-Object -ComObject wscript.shell
$ShortCutList = Get-ChildItem -Path $env:UserProfile\Desktop\*.lnk
foreach ($Shortcut in $ShortCutList) {
$thisShortCut = $WSHShell.CreateShortCut($Shortcut.FullName)
if ($thisShortCut.TargetPath -match '\\Appdata\\Roaming\\Citrix\\SelfService\\') {
Write-Verbose -Message ('Deleting Citrix shortcut: {0}' -f $Shortcut.BaseName)
Remove-Item -Path $ShortCut.FullName -Force
}
$null = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($thisShortCut)
Remove-Variable -Name thisShortCut
}
$null = [System.Runtime.InteropServices.Marshal]::ReleaseComObject($WSHShell)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment