Recently I was tasked to create FSLogix App Masking Rules and I wanted to do this automatically. Browsing the web I found a handy PowerShell function that extract the executable path from all Start Menu icons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# https://www.computerperformance.co.uk/powershell/function-shortcut/ # PowerShell function to list Start Menu Shortcuts Function Get-StartMenu{ Begin{ Clear-Host $Path = "$Env:ProgramData\Microsoft\Windows\Start Menu\Programs" $x=0 } # End of Begin Process { $StartMenu = Get-ChildItem $Path -Recurse -Include *.lnk ForEach($ShortCut in $StartMenu) { $Shell = New-Object -ComObject WScript.Shell $Properties = @{ ShortcutName = $Shortcut.Name LinkTarget = $Shell.CreateShortcut($Shortcut).targetpath } New-Object PSObject -Property $Properties $x ++ } #End of ForEach [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null } # End of Process End{ "`nStart Menu items = $x " } } #Example of function in action: Get-StartMenu | Export-Csv .\start.csv |
With all these path’s in an exported CSV file it’s very easy to run a ForEach loop to create FSLogix App Masking Rules. Unfortunately the cmdlets need some additional work to make that happen!
Anyhow the CSV file came handy the next day when I was creating Citrix Workspace Environment Application shortcuts in the Cloud and guess what? You need to manually upload the .ico files. What a PITA!
So how do you do that? Well you can use the awesome free Master Packager to save the .ico file from an MSI package, but what about .exe and .dll? And how can we automate all this?
Guess what, there’s a fancy Module in the PowerShell Gallery you can use. I’am setting ErrorActionPreference to get rid of all the error messages because many links points to files like .txt which doesn’t contain an icon.
1 2 3 4 5 6 7 8 9 |
#$ErrorActionPreference= 'silentlycontinue' $csv = Import-Csv .\start.csv Install-Module -Name IconExport -Force Import-Module -Name IconExport foreach ($line in $csv) { Export-Icon $line.LinkTarget -Directory C:\Icons } |