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.