Wednesday, 22 August 2012

PoSH

Powershell Rocks!

At the very heart of my entire build, deployment and DevOps work is Powershell. I can't honestly imagine life without this absolute Gem. 

It enables me to build, deploy and manage extremely complex solutions, and its free! What is there not to love! 

Parallel processing

The single biggest advantage of PoSH in my opinion is its ability to run background jobs. It's by this inherent feature that I've managed to decimate the running times of some very long running processes.

For instance
  • Build times from 45 minutes to 4
  • Deployment times from 35 minutes to 3
There is a standard limitation of 20 concurrent processes per host, but this is easily modified. However, there does come a point I've discovered where you can over work your local computer, so how many jobs you choose to run is very much determined by just how much CPU power each process will consume.

MSBuild for instance, even when set to run in multi-processor mode, doesn't really push the CPU to its limits. I've found that I can run approximately twice as many MSBuild processes as cores available, and my CPU then averages around 90-95%. 

MSTest is another matter. MSTest can and frequently does run a core upto 100%, so with MSTest, I run as many as I can, leaving a single core left to idle and take care of the system.

Remote processing

Another fantastic ability is running processes remotely. Again, this is another feature that I have used extensively to scale up the processing power available to my long running tasks. What could be better than running 20 jobs on a single host? Running 100 over a network! 

Not every action is suitable for remote processing. MSBuild for instance, would require source code to be copied remotely, or given network access, and the overhead of this typically takes away the advantages of remote processing.

MSTest on the other hand, works on test containers and dependent assemblies. Quick to copy, and can take several minutes to process, which makes MSTest an ideal candidate for remote processing.

XML

Handling XML is so ridiculously easy with PoSH that I've almost forgotten what XML looks like. Many of my tasks and processes consume, create and share XML objects without ever realising that they're dealing with XML. 

A good example was NCovers XML reports. Hideous to casual reader, but so very easily processed using PoSH and transformed into very meaningful radar diagrams using MSCharts.

Equally, PoSH can consume XML via web services, which opens up a whole world of possibilities when interacting with APIs and cloud services. 

.NET

If I were to descrive PoSH to a programmer, I would basically say that it's a "Scripted .NET" engine. Without any real effort, my PoSH scripts and modules frequently employ methods within assemblies to perform tasks.

An example of this would be the .NET MS Chart Controls. By taking XML from NCover, I was able to transform it into some very effective radar diagrams all within PoSH. 

Cmdlets

From Microsoft, nearly every product or service, is a Cmdlet designed to make interaction from PoSH that little bit easier using native PoSH syntax and conventions.

I frequently use Cmdlets to interact with
  • SQL Server
  • SQL Analysis Services
  • App Fabric Caching
  • IIS
  • Windows
  • Windows Remote Management (WinRM)
  • Azure services
  • And loads more.... 

Why I love PoSH?

Over the years, I've come to be very mistrusting of proprietary frameworks and cloud services.

In the past few years, I've chosen to develop my own build and deployment framework using PoSH, rather than using CCNet, TeamCity, TFS etc. And I've never looked back.

What I like about PoSH is that it works like developer glue. Whatever products and services my dev teams decide to use, I know that using PoSH I can bring them all together with PoSH. I am not locked into any one approach, service or framework. I can also be choosy, taking only what I need from any given application or service, and ignoring the bloat that I would otherwise be forced to use.

Using PoSH, I could substitute my source control repository tomorrow without having any affect on any other part of my build and deployment pipeline. Equally, I could change test suites, code coverage tools, even deployment hosts. I don't have to wait for updates to use the latest tool sets, and I'm free to choose products from competing vendors. 

PoSH is freedom, flexibility and power.