Matthew Crews Matthew Crews - 10 months ago 72
Node.js Question

Execute Powershell script from Node.js

I've been looking around the web and on Stackoverflow but hadn't found an answer to this question. How would you execute a Powershell script from Node.js? The script is on the same server as the Node.js instance.

Answer Source

You can just spawn a child process "powershell.exe" and listen to stdout for command output and stderr for errors:

var spawn = require("child_process").spawn,child;
child = spawn("powershell.exe",["c:\\temp\\helloworld.ps1"]);
    console.log("Powershell Data: " + data);
    console.log("Powershell Errors: " + data);
    console.log("Powershell Script finished");
child.stdin.end(); //end input