Home

Awesome

PshOdata Module

2008R2 and 2012 versions of Windows contain a feature called IIS Odata Extensions. An IIS application that uses the extensions can be configured to create a RESTful web service that will run PowerShell cmdlets and return the objects as either JSON or XML. The PshOdata Module makes it easy to generate the files used to create these endpoints.

Example Usage

$class = New-PshOdataClass Process -PK ID -Properties 'Name','ID'
$class |Add-PshOdataMethod -verb get -cmdlet get-process -Params Name, ID -FilterParams Name
$class |Add-PshOdataMethod -verb delete -cmdlet stop-process -FilterParams ID
$class |New-PshOdataEndpoint

The above will create the files required to allow GET and SET http methods to a url like this:

The endpoint will return Process objects that contain Name and ID Properties that are taken from Get-Process. It will also allow the DELETE method to call Stop-Process when the PK is used.

Files Generated

The New-PshOdataEndpoint function will create a set of files in an odata folder within the current working directory by default.

The following files are generated:

Installation of the files

Currently, we do not have a method to create the IIS portion of the Odata extensions. We plan on solving this with a function soon. However, in the meantime, you can use the OdataSchemaDesigner in order to have your first endpoint created, and then you can use these cmdlets to generate the files you need for your Odata service.

The following steps must be performed on Windows Server 2012 box that does NOT have R2.

  1. Add-WindowsFeature ManagementOdata # Install the odata extensions
  2. Install Visual Studio Isolated Shell - http://www.microsoft.com/en-us/download/details.aspx?id=1366
  3. Install the odata extension isolated installer - http://archive.msdn.microsoft.com/mgmtODataWebServ/Release/ProjectReleases.aspx?ReleaseId=5877
  4. Launch the Management Odata Schema Designer from the start screen
    1. File-> New File -> Management Odata Model
    2. Right-Click and select Import Cmdlets
    3. Local Computer -> Next
    4. Installed Windows PowerShell Modules -> Microsoft.PowerShell.Management
    5. Choose Service -> Next
    6. Uncheck CREATE and UPDATE. Only Get should be selected. Next.
    7. Next
    8. Choose any key and click Next.
    9. Next
    10. Finish
    11. Right click in the designer and choose Publish Odata Endpoint
    12. Select the local computername and fill out a username and password. Choose a name for the site (odata is a good choice). Finally select a port number and then click Publish.

Once the IIS server has the site created. You can use the cmdlets in this module to generate the schema.xml, schema.mof, and rbacconfiguration.xml files. Copy these files into the application you created (c:\inetpub\wwwroot\odata). Perform an IISReset. Enjoy your web service.

Notes