Es necesario instalar:
- Node-powershell
1 |
npm i -S node-powershell |
- Express
1 |
npm install --save express |
Código para listar procesos de PowerShell con Node-PowerShell (Node.JS) y mostrarlos en una web con Express (fichero.js)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
const shell = require('node-powershell'); const express = require('express') const app = express() let ps = new shell({ executionPolicy: 'Bypass', noProfile: true }); ps.addCommand('Get-Process | ConvertTo-Html -Property Name, Path, Company') ps.invoke() .then(output => { console.log(output); app.get('/', function (req, res) { res.send(output); }) }) .catch(err => { console.log(err); ps.dispose(); }); app.listen(3000, function () { console.log('Example app listening on port 3000!') }) |
El código se ejecuta escribiendo en PowerShell o en CMD el siguiente comando
1 |
node fichero.js |
Resultados: