【问题标题】:Executing Exchange PowerShell commands from a CMD Prompt using VBscript使用 VBscript 从 CMD 提示符执行 Exchange PowerShell 命令
【发布时间】:2014-12-16 03:39:43
【问题描述】:

我正在创建一个 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"" "

请帮我解决这个问题。

【问题讨论】:

  • 我确信还有更多内容,但在这种情况下从另一个 shell 调用 shell 是多余的。我会从中删除 cmd 组件。另外,你没有说错误发生在哪里。当然,我希望它在第 3 行,但是您实际上是脚本中的<br> 吗?那会导致错误吗?
  • 您是否有理由不只使用 PowerShell。在您的情况下,Cscript 调用 Cmd 调用 PowerShell ?

标签: windows powershell vbscript cmd


【解决方案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"

【讨论】:

  • 我需要调用exshell.psc1文件来运行或读取.ps1文件。
猜你喜欢
  • 2011-07-24
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-05
  • 1970-01-01
  • 2012-11-23
  • 2013-06-08
相关资源
最近更新 更多