1

I have a requirement of running powershell script in silent mode through vbscript(cscript.exe).

Basic steps for script are as follow.

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 script

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

Atthis point, I like the powershell script to write to vbscript(cscript.exe) console.

I am running vb script as follow.

cscript d:\basic\script.vbs

Is there any work around for this requirement.

Muhammad Sadiq
  • 103
  • 3
  • 8
  • Possible duplicate of [I need execute a command line in a Visual Basic Script](http://stackoverflow.com/questions/11501044/i-need-execute-a-command-line-in-a-visual-basic-script) – Andrew Savinykh Feb 18 '16 at 00:22

1 Answers1

0

As explained in the answer to the question that I linked as a possible duplicate, you can do something like this:

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
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158