BT

InfoQ Homepage News Written in PowerShell, a HTTP API for Executing PowerShell Scripts

Written in PowerShell, a HTTP API for Executing PowerShell Scripts

Bookmarks

REST and REST-like interfaces over HTTP are all the rage these days. Not too long ago we told you about Oracle releasing a prototype of their HTTP-based API for MySQL. Not to be out done, Steve Lee of Microsoft has released sample code for exposing PowerShell over HTTP.

This isn’t the first remote interface for PowerShell, the credit for that goes to the PowerShell Remoting Protocol (PSRP). But this protocol is designed to be used from a Windows-based machine in a PowerShell console. Unlike HTTP, PSRP is not meant to be programmatically accessed by arbitrary programs running on arbitrary operating systems.

The “Simple HTTP api for executing PowerShell scripts” is itself just a PowerShell script. So changing functionality just requires modifying a single file, no compilation needed.

Internally the script uses System.Net.HttpListener. For security it defaults to Integrated Windows Authentication, but this can be overridden at the command line. The sample doesn’t demonstrate using SSL, but that should be easy enough to add it if you are already familiar with using SSL certificates in conjunction with the HttpListener class.

More important to some, this is an excellent tutorial for authoring PowerShell modules. Weighing in at less than 300 lines including comments and whitespace, the code is surprisingly easy to follow.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.