I have a powershell script that should make a shortcut to a image on the desktop, however, when I run the script, I get the error:
Unable to save shortcut "C:\users\muffin\desktop\a.png C:\users\muffin\Desktop\testshortcut.lnk".
At C:\Users\muffin\Downloads\setup.ps1:10 char:9
+ $Shortcut.Save()
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException
my code is as follows:
function Set-Shortcut {
param ( [string]$SourceLnk, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($SourceLnk)
$Shortcut.TargetPath = $DestinationPath
$Shortcut.Save()
}
Set-Shortcut("C:\users\muffin\documents\a.png", "C:\users\muffin\Desktop\testshortcut.lnk")
I have checked that the file exists, and I'm fairly sure that I haven't made any spelling errors.