JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q32689F
  • License MIT

Hosts a PowerShell process to execute asynchronous PowerShell commands and get data back fast.

Package Exports

  • powershell-host
  • powershell-host/PowerShell.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (powershell-host) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PowerShell-Host

PowerShell-Host is a JavaScript library which hosts a PowerShell process to allow running commands and getting the results back quickly. PowerShell Exceptions are intercepted the Exception.Message is emitted to stderr.

This implementation uses Promises to make things easy to use:

  • Output on stderr will be rejected.
  • Output on stdout will be resolved.

Example:

You can use the in-built ConvertTo-Json applet to make parsing the data easy.

import { PowerShell } from 'powershell-host';

const ps = new PowerShell();

const run = async () => {
    await ps.init();
    const json = await ps.exec('Get-PsDrive | Select Name, Root | ConvertTo-Json');
    const obj = JSON.parse(json);
    // Newer versions of PowerShell can use ConvertTo-Json -ToArray to avoid forcing an array here
    const result = Array.isArray(obj) ? obj : [obj];
    result.forEach((drive) => console.log(drive.Name));
};

run()
    .catch((err) => {
        console.error(`ERROR: ${err.message}`);
    })
    .finally(() => {
        ps.deinit();
    });