Powershell 的快捷方式 (.lnk) - 为什么它不起作用

Shortcut (.lnk) with Powershell - why does it not work

(好的 - 我仍然遇到一个错误)

这到底是怎么回事?我需要做的就是在一行中执行 this 。 像这样:

PS C:\Users\Horn.Ruben> $shell = New-Object -com "WScript.Shell"; $TestBackupAddin = $shell.CreateShortcut("C:\ClusterStorage\Volume2\test.lnk"); $TetsBackupAddin.TargetPath = "C:\ClusterStorage\Volume2\_VMBackups150113-0844\TestBackupAddin"; $TestBackupAddin.Save();

现在我得到的唯一错误是:

The property 'TargetPath' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:123
+ $shell = New-Object -com "WScript.Shell"; $TestBackupAddin = $shell.CreateShortc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

两个目录都需要存在才能使用吗?

PS:我需要在一行中将所有这些 运行(稍后创建多个快捷方式)

尝试

$shell = New-Object -ComObject WScript.Shell

而不是

$shell = New-Object -ComObjetct WScript.Shell

尝试

$TestBackupAddin = $shell.CreateShortcut

而不是

$TetsBackupAddin = $shell.CreateShortcut