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

Powershell写入vbscript控制台(cscript.exe),powershell,vbscript,powershell-2.0,windows-scripting,Powershell,Vbscript,Powershell 2.0,Windows Scripting,我需要通过vbscript(cscript.exe)以静默模式运行powershell脚本。 脚本的基本步骤如下所示 cscript d:\basic\script.vbs vbscript WScript.StdOut.WriteLine "Welcome..." WScript.StdOut.WriteLine "First Step..." WScript.Sleep Int(2000) Set objShell = CreateObject("Wscript.Shell"): objS

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

脚本的基本步骤如下所示

cscript d:\basic\script.vbs
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

对于这个要求,是否有任何解决办法。

正如我作为可能的副本链接的问题的答案中所解释的,您可以这样做:

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

正如我作为可能的副本链接的问题的答案中所解释的,您可以这样做:

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
可能的重复可能的重复