npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

powershell-command-executor

v1.1.3

Published

Provides a registry and gateway for execution powershell commands through long-lived established remote PSSessions via a stateful-process-command-proxy pool of powershell processes

Downloads

102

Readme

powershell-command-executor

Node.js module that provides a registry and gateway for execution of pre-defined powershell commands through long-lived established remote PSSessions.

NPM

Overview

This Node.js module builds on top of stateful-process-command-proxy to provide a higher level API for a registry of pre-defined commands, specifically for various powershell operations agains Office365; or any powershell command really, you just need to configure them. The module provides a simplified interface to pass arguments to various "named" commands, sanitize the arguments and return the results. This module supports concepts that would permit the construction of a higher level interface to this system, such as via a REST API or user interface... see powershell-command-executor-ui for a working example of this concept in an useable implementation.

Alt text

Concepts

psCommandExecutor.js

This provides the PSCommandService class which is a wrapper around StatefulProcessCommandProxy which lets a caller invoke "named" commands passing an map/hash of arguments. PSCommandService will generate the actual command and pass it to the StatefulProcessCommandProxy for execution and return the results. PSCommandService must be created passing an configured instance of StatefulProcessCommandProxy and a "registry" of commands. You can see an example of what a command registry looks like within o365Utils.js. You don't have to use the latter registry.. you can create your own or just augment it with your own set of commands that you want to make available through PSCommandService.

o365Utils.js

This script simply exports a few useful pre-defined parameter sets (that one would pass to the constructor of StatefulProcessComamndProxy) for the initialization, destruction and auto-invalidation of "powershell" processes who connect to o365 and establish a remote PSSession that will be long lived. (and validate that the session is still legit)

Exchange authentication

o365Utils.js init command getO365PSInitCommands is using a deprecated authentication method

Mictosoft has added Exchange Online PowerShell V2 that supports cerificate based authentication.

Full setup is descibed here

Three sets of init commands are availiable as of version 1.1.0:

  • getO365PSInitCommands - backward compatible old basic authentication
  • getO365PSKeyInitCommands - new Exchange authentication with private key and password
  • getO365PSThumbprintInitCommands - new Exchange authentication with the thumb print for the certificate

Usage

  1. Configure your o365 tenant with a user with the appropriate permissions to manage o365 via Powershell. See this article to get going

  2. Use powershell-credential-encryption-tools to create an encrypted credentials file and secret key for decryption. SECURE these files!

  3. From within this project install the necessary npm dependencies for this module, including stateful-process-command-proxy. You can checkout the latter manually and do a npm install stateful-process-command-proxy

  4. Configure example.js/example_key_auth.js/examplekey_thumb_auth.js appropriately, in particular the initCommands for the StatefulProcessCommandProxy; the paths to the items you created via the second step above

  5. Tweak the group that is fetched at the bottom of example.js/example_key_auth.js/examplekey_thumb_auth.js

  6. There is also a unit-test (test\all.js) for the command registry in o365Utils.js which gives an example of usage for all thre possible Exchange connect variations.

History

v1.1.3 - 2024-11-14
    - Added support for [multivalued parameters](https://learn.microsoft.com/en-us/exchange/modifying-multivalued-properties-exchange-2013-help) in commands

v1.1.2 - 2022-07-06
    - Added support for usage of reserved powershell variables in commands [$null, $true, $false]

v1.1.1 - 2020-12-07
    - Fixed bug import of custom commands if provided for certificate based auth

v1.1.0 - 2020-12-03
    - Added option for key and thumbprint based Exchange authentication

v1.0.0 - 2016-06-08
    - Get-DistributionGroupMember - added "-ResultSize Unlimited"

v1.0-beta.7 - 2015-02-10
    - Add semi-colins to sanitization

v1.0-beta.6 - 2015-02-06
    - Bug fix to injection

v1.0-beta.5 - 2015-02-06
    - Further improvement for argument injection

v1.0-beta.4 - 2015-02-05
    - Fixes to quote sanitization, bug fixes

v1.0-beta.3 - 2015-01-30
    - Tweaks to init commands

v1.0-beta.2 - 2015-01-28
    - Whitelisting of commands

v1.0-beta.1 - 2015-01-28
    - Initial version

Related Tools

Have a look at these related projects which support and build on top of this module to provide more functionality

  • https://github.com/bitsofinfo/stateful-process-command-proxy - The core dependency of this module, provides the actual bridging between node.js and a pool of external shell processes
  • https://github.com/bitsofinfo/powershell-command-executor-ui - Builds on top of powershell-command-executor to provide a simple Node REST API and AngularJS interface for testing the execution of commands in the registry
  • https://github.com/bitsofinfo/meteor-shell-command-mgr - Small Meteor app that lets you manage/generate a command registry for powershell-command-executor

notes

npm login
npm publish