Powershell写入vbscript控制台(cscript.exe)

时间:2016-02-17 23:58:04

标签: powershell vbscript powershell-v2.0 windows-scripting

我需要通过vbscript(cscript.exe)以静默方式运行powershell脚本。

脚本的基本步骤如下。

的VBScript

WScript.StdOut.WriteLine "Welcome..."
WScript.StdOut.WriteLine "First Step..."
WScript.Sleep Int(2000)
Set objShell = CreateObject("Wscript.Shell"): objShell.Run "powershell -nologo -file D:\basic\child.ps1" ,0,true
WScript.StdOut.WriteLine "Script Completed."
WScript.Sleep Int(5000)

powershell脚本

Write-Host "Some Text Printed"
Start-Sleep -s 2

至此,我喜欢使用powershell脚本写入vbscript(cscript.exe)控制台。

我正在运行vb脚本,如下所示。

cscript d:\basic\script.vbs

是否有任何解决此要求的工作。

1 个答案:

答案 0 :(得分:0)

正如在我作为可能重复链接的问题的答案中所解释的那样,您可以执行以下操作:

WScript.StdOut.WriteLine "Welcome..."
WScript.StdOut.WriteLine "First Step..."
WScript.Sleep Int(2000)
res = getCommandOutput("powershell -nologo -file D:\basic\child.ps1")
WScript.StdOut.Write res
WScript.StdOut.WriteLine "Script Completed."
WScript.Sleep Int(5000)

Function getCommandOutput(theCommand)

    Dim objShell, objCmdExec
    Set objShell = CreateObject("WScript.Shell")
    Set objCmdExec = objshell.exec(thecommand)
    getCommandOutput = objCmdExec.StdOut.ReadAll

end Function