0

I am trying to run powershell script from JScript. powershell will pop up but the script is not getting executed.

Below is the sample code

var WSH = new ActiveXObject("WScript.Shell");
var exec= WSH.Exec("powershell .\test1.ps1");
exec.StdIn.Close();

test1.ps1 is a simple script which creates textfile.

redumpt
  • 167
  • 13

1 Answers1

0

Try putting the full path to c:\path\to\test1.ps1. I guess there is a different idea of "the current directory" which .\ is not finding the right file. Also try putting -NoExit on the end of the powershell command line, and maybe the window will stay open and you can read any error message.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • changed it to full path with -NoExit , the error was because of ExecutionPolicy of powershell. It worked after fixing the path and executionpolicy like this WSH.Exec("powershell -ExecutionPolicy RemoteSigned c:\path\to\test1.ps1") – redumpt Jan 16 '22 at 16:09