Powershell:使用参数创建 LNK

Powershell: Create LNK with Parameter

我迷上了这个线程here,我试图让它成为一个功能来创建 LNK 文件到 Powershell 脚本(因为我厌倦了手动制作)。

function MakeLink {
param 
(
    [Parameter(Mandatory=$true,Position=0)]
    [System.String]
    $Script
)

$wshShellObject = New-Object -com WScript.Shell
$userProfileFolder = (get-childitem env:USERPROFILE).Value
$wshShellLink = $wshShellObject.CreateShortcut($userProfileFolder+"\Desktop\MeinLink.lnk") 
$wshShellLink.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"+$Script
$wshShellLink.WindowStyle = 1
$wshShellLink.IconLocation = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" 
$wshShellLink.WorkingDirectory = $programFilesFolder + "\Internet Explorer\" 
$wshShellLink.Save()

} $脚本 = "C:\PowerVS\PowerVS.ps1" MakeLink $脚本

一切正常,除了第 12 行的 +$Script。目标路径似乎不接受任何参数(脚本正常工作需要这些参数 -.-) 我已经尝试使用

$wshShellLink.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" $Script
$wshShellLink.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe $($Script)"

但这些也不起作用。

有人知道如何解决这个问题吗?

几乎在我写这个帖子的时候,我就找到了答案:

$wshShellLink.Arguments = $脚本

为什么我之前找了几个小时都没有找到那个? -.-