【发布时间】:2019-05-30 14:24:21
【问题描述】:
我有一个旧脚本,它在特定情况下使用一些额外的参数调用自己。如果通过常规的 powershell 窗口运行,这将有效
$spath = $script:MyInvocation.MyCommand.Path
$FilePathWithQuotes = '"{0}"' -f $spath
powershell -file $FilePathWithQuotes -NestedCall @ExtraArgs
但如果它通过 ISE 运行,我会收到此错误。
powershell : Add-Type : 无法将参数“路径”绑定到目标。 异常设置“路径”:“在 D:\Deploy\File 找不到路径 部署.ps1:39 字符:5 + powershell -file $FilePathWithQuotes -NestedCall @ExtraArgs + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo : NotSpecified: (Add-Type : Cann...nnot find path :String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
我添加了第二行以确保空格不是问题,但它在 ISE 中仍然失败。 想法?我在 ps 5.1 上
【问题讨论】:
-
查看控制台/ise/vscode 的答案:stackoverflow.com/questions/48511874/…
-
$script:MyInvocation.MyCommand.Path也应该在 ISE 中工作(假设选项卡的内容已保存到脚本文件中)。顺便说一句,没有必要将文件路径包含在嵌入的双引号中(我很惊讶它甚至可以工作)。请注意错误与Add-Type的关系,因此您需要显示该调用以进行进一步诊断。