Wednesday, July 30, 2014

Exploring PowerShell cmdlets

I have been working with PowerShell for a number of years now. In that time I have generally only created scripts (like you would in Bash) and build scripts, using the awesome Psake build tool.

I never had a need to create a module, advanced function, cmdlet or any of the other fancy features that PowerShell supports.

However, today I began looking at interaction with the Octopus Deploy server. At work we have a large number of variables that we need to create and maintain. The web interface is not bad, but it does not allow bulk edits. After searching for a way to import variables, perhaps via a CSV file, I found no such feature exists.

The entire backend of Octopus is accessible through a REST api, so I started looking at editing JSON and PUTting it to the server, but that seemed cumbersome. Then I came across the Octopus.Client C# library. It is a .NET api over the REST api.

First I thought about writing a command line tool or adding the functionality to their octo.exe command line tool. But the type of interaction I was looking for called for a more interactive shell-type experience than a command line tool gives. So I started to think about writing a REPL type tool, when I realized that PowerShell already gives you all the good parts of the infrastructure. What I needed was a set of shell scripts. Given that the api is .NET, it became obvious that PowerShell cmdlets were I what I was after.

Both the System.Management.Automation and Octopus.Client apis are really straightforward to use. It didn’t take long to get a good collection of cmdlets together. Hence, Octopus-Cmdlets was born.

No comments:

Post a Comment