BT

Written in PowerShell, a HTTP API for Executing PowerShell Scripts

| by Jonathan Allen Follow 637 Followers on Oct 03, 2014. Estimated reading time: 1 minute |

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

Tell us what you think

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

Email me replies to any of my messages in this thread
Community comments

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

Discuss
BT