我正在创建一个VBScript,它将从命令提示符运行Exchange PowerShell命令。
当我尝试运行下面的脚本时,expected end of statement
出现了。
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe ""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"" -psconsolefile ""C:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1"" -file ""C:\script\script.ps1"" "
请帮我解决这个问题。
答案 0 :(得分:1)
(1)<br>
必须去。
(2)避免你的报价同步,如
... -file """C:\script\script.ps1" "
使用更有条理的方式构建复杂的字符串:
Option Explicit
Function qq(s) : qq = """" & s & """" : End Function
Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
Dim sCmd : sCmd = Join(Array( _
"%comspec%" _
, "/c" _
, qq("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe") _
, "-psconsolefile" _
, qq("C:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1") _
, "-file" _
, qq("C:\script\script.ps1") _
))
WScript.Echo sCmd
输出:
cscript 26477799.vbs
%comspec% /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -psconsolefile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1" -file "C:\script\script.ps1"