Calling Powershell with WshShell.Exec() method hangs the script
You have to close StdIn:
var shell = new ActiveXObject("WScript.Shell");var exec = shell.Exec('powershell -noninteractive -noprofile -Command "& { echo Hello_World ; Exit }"');exec.StdIn.Close();WScript.Echo(exec.StdOut.ReadAll());
Microsoft said:
StdIn is still open so PowerShell is waiting for input. (This is an"implementation consideration" that we're hoping to fix in V2. ThePowerShell executable gathers all input before processing.) Soobjexec.StdIn.Close() needs to be added.
Use:
powershell.exe -noninteractive -noprofile -command $host.version
as your string. For more complicated groups of commands, use this syntax:
powershell.exe -noninteractive -noprofile -command "& { $host.version; $host.version }"