I usually never have programming problems because I can easily find the answer to most of them. But I am at my wits' end on this issue.
The well known way of creating a Windows shortcut in Powershell is as follows:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("F:\path\to\shortcut.lnk")
$Shortcut.TargetPath = "F:\some\other\path\to\targetfile.txt"
$Shortcut.Save()
However, this method has a shortcoming which I'm starting to be bothered by more and more: it does not work when the filename has special characters eg a smiley face in filename:
"targetfile .txt"
I researched the issue and discovered here that the WshShortcut object and WScript cannot accept unicode in the filenames. It only seems to work for a simple set of characters. Of course, when you right-click the file in Windows and select "Create Shortcut" Windows has no problems creating the shortcut with the special character in it.
Someone scripted in C# an alternative way to create shortcuts using Shell32 but I don't know if it can be done in Powershell. And it looks like an old method which might not work in newer builds of Windows.
Would someone please help me with this issue? How to create a Windows shortcut in Powershell to a file whose filename has special characters in it?
When in doubt, use C#: