Tips for making it easier to consume .NET APIs from PowerShell

2012-10-02 12:45:26 +0000

Prefer enum types over constants or properties

If you use an enum, PowerShell can implicitly convert the value:


If you use constants or static properties, you need a load more typing.

Prefer synchronous methods to event-based asynchronous methods

PowerShell 2.0 can subscribe to .NET events, and it’s pretty powerful. It’s just fairly verbose. Given the choice between a synchronous (blocking) method and the Event-based Asynchronous Pattern, provide a synchronous interface.

Of course, you could provide both, but it’s all about await these days anyway, which PowerShell doesn’t support.

Don’t use explicit interface implementation

It’s not accessible from PowerShell.