在VBScript文件中调用PowerShell脚本时,如何使用嵌套引号?

在VBScript文件中调用PowerShell脚本时,如何使用嵌套引号?,powershell,vbscript,Powershell,Vbscript,我是VBScript和PowerShell新手。我有一个PowerShell脚本,当我从命令行调用它时,它可以正确运行。但是,当我尝试从VBScript调用它时,它会运行,但不会执行任何操作 我在CLI上使用的命令是 powershell.exe -nop -exec bypass -noni -command "& { . C:\<censored path>\testscript1.ps1; Get-Test }" powershell.exe-nop-exec-byp

我是VBScript和PowerShell新手。我有一个PowerShell脚本,当我从命令行调用它时,它可以正确运行。但是,当我尝试从VBScript调用它时,它会运行,但不会执行任何操作

我在CLI上使用的命令是

powershell.exe -nop -exec bypass -noni -command "& { . C:\<censored path>\testscript1.ps1; Get-Test }"
powershell.exe-nop-exec-bypass-noni-command“&{.C:\\testscript1.ps1;Get Test}”
这很有效。当我运行下面的vbscript代码时,我没有得到任何结果

Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell.exe -nop -exec bypass -noni -command &""& { . C:\<censored path>\testscript1.ps1; Get-Test }" &"")
Set objShell=CreateObject(“Wscript.shell”)
运行(“powershell.exe-nop-exec-bypass-noni-command&&{.C:\\testscript1.ps1;Get Test}”和“)
我做错了什么

PS:将我的命令精简为:

objShell.run("powershell.exe -nop -exec bypass -noni -command "& { . C:\<censored path>\testscript1.ps1; Get-Test }" ")
objShell.run(“powershell.exe-nop-exec-bypass-noni-command”&{.C:\\testscript1.ps1;Get Test}”)

我得到一个代码800A0408-左括号的无效字符错误。我已尝试转义这两个括号,但仍然得到相同的错误。

您可以尝试类似的操作:

PSCommand = "powershell.exe -nop -exec bypass -noni -command" & DblQuote("& { . C:\<censored path>\testscript1.ps1; Get-Test }")&""
MsgBox PSCommand 
set objShell = CreateObject("wscript.shell")
objShell.Run PSCommand
'****************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'****************************************************************
PSCommand=“powershell.exe-nop-exec旁路-noni-command”&DblQuote(&{.C:\\testscript1.ps1;Get Test}”)&
MsgBox psc命令
设置objShell=CreateObject(“wscript.shell”)
运行psjshell命令
'****************************************************************
函数DblQuote(Str)
DblQuote=Chr(34)和Str&Chr(34)
端函数
'****************************************************************