简体   繁体   中英

How to run powershell script file from JScript?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM