Skip to content

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

Notifications You must be signed in to change notification settings

bitsofinfo/powershell-command-executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

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 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

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

History

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

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •