Home > Back-end >  How to create a Windows Shortcut in Powershell to a file with special characters in filename?
How to create a Windows Shortcut in Powershell to a file with special characters in filename?

Time:11-30

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

  • Related