Wednesday, July 21, 2010

Powershell Scripting Book - first thoughts

As part of my endeavour to learn a new language this year (and hopefully every year), I decided to improve my .NET and general Windows development workflow with Powershell. It's not only a great scripting tool, but a complete language, and actually quite handy as a REPL too, when working with .NET types.

In order to maximize my learning time, I turned to Manning and bought the 'early access program' book for Windows Powershell In Action. I am a huge fan of the early access program, and have bought more than 10 books now.. Again I wasn't disappointed, as it is a good entry level book to the syntax and idioms that make Powershell so, well.. powerful.

Once I had mastered the syntax, using the canned examples within the book, I decided to take the plunge and write a few 'real world' scripts. It didn't take me too long until I had started incorporating Powershell into my everyday development cycle.

My 'new work' script looks something like this:

[string]$name = $(throw "a branch name is required")

. .\Scripts\Utilities.ps1


Invoke-Expression .\Create-Branch.ps1 "BUG_$name"
Invoke-Expression .\Setup-Config.ps1
Invoke-Expression .\Build-Source.ps1
Invoke-Expression .\Build-Database.ps1


The whole process automates a lot of the drudgery of creating a branch, switching to it, patching the many config files (via XPath), doing a full build, rebuilding the database, etc. Fantastic!

What is more surprising is that these processes were done each and every time by each developer manually until I suggested we script them.. What's more, each had their own special way to achieve the end result, which made things difficult when we integrate branches and get a consistent working environment.

I am still trialling these scripts, and the many others that I have written to manage random files and processes on the fly, however I am having lots of fun and have even managed to remove some drudgery from a home-centric file operation ritual I do all the time.. This will have to wait for another post however..

HINT: I'm downloading and transferring podcasts to my phone.. (I use RSS via google reader and DownThemAll currently - it's very manual..)