I'm trying to use PowerShell to create a shortcut that targets a file on a mapped drive. This script will be running before the drive is actually mapped, though. Here's the code:
$Shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut("$Env:USERPROFILE\Desktop\Test.lnk")
$Shortcut.TargetPath = "X:\Folder With Spaces\This is a long filename.txt"
$Shortcut.Save()
Because the "X" drive doesn't exist yet, this is what the shortcut's "Target" field ends up saying:
Windows XP: X:\Folder_W\This_is_.txt
Windows 7: X:\Folder_With_Spaces\This_is_a_long_filename.txt
Both operating systems remove the surrounding double quotes and convert the spaces into underscores. Windows XP also truncates the folder and filenames to 8 characters.
Is there a way around this problem?