title: How to execute windows powershell command using childprocess and nodejs?
body: <p>I am trying to run a powershell command through a nodejs script. I have found the following two articles which have shown me something similar to what I am trying to acheive:
  <a href="https://stackoverflow.com/questions/15919347/how-to-execute-windows-shell-commands-cmd-exe-with-node-js">Execute Windows Commands with Nodejs</a>
  <a href="https://stackoverflow.com/questions/10179114/execute-powershell-script-from-node-js">Execute powershell script from nodejs</a></p>
  
  <p>On a button click event, I am trying to list the usb devices currently attached to the system along with its Drive Letter (C, D, E etc). If I run the command in the powershell on its own, it works (I am unable to get it to display the drive letter though). However, if I run it as part of my script it does not work. Below is my code:</p>
  
  <pre><code>if (process.platform === 'win32' || process.platform === 'win64') {
      exec("powershell.exe",["GET-WMIOBJECT win32_diskdrive | Where { $_.InterfaceType –eq 'USB' }"], function (err, stdout, stderr) {
          console.log(err);
          console.log(stdout);
          console.log(stderr);
      });
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>