Dr. Script or: How I Learned to Stop Worrying and Love Powershell

Published on
Reading time
Authors

Powershell has been with us now since late 2006 but my experience is that widespread understanding and use of it is still very restricted within the .NET developer community.  If you're a Windows administrator, operator or release manager I'm sure you're all over it.  If you're job description doesn't fit in one of those three groups and you're not inclined to understand how your software will be deployed or operated then the chances are you don't know much about Powershell.

I have to say that Powershell's syntactic differences to the "standard" C# most developers would know is an easy place to start disliking working with it (for example it's not "==" for equals it's "-eq" and null becomes $null).  I say to those developers: it's worth persevering because you stand to gain a lot once you get your head around it.

If you need to deploy something to test or debug it or you have an awkward environment with which to work with (I'm looking at you SharePoint 2010) then you will save yourself a lot of time by scripting out as much manual stuff as you can.  Your release managers and ops teams will also love you if you can provide scripts that allow them to deploy without needing to perform a massive number of manual steps (if you ever want to get to the Continuous Deployment nirvana you can't really avoid working with a scripting language).

I'm currently working on a project that includes the need for 84 IIS Websites in a load balanced environment.  These sites follow a pattern - think I want to manually configure 84 IIS instances?  Right.  I have a Powershell script that will setup each site including a new local windows login for the Application Pool, setup the Application Pool (including user), create the Website (including folders and holding page and association with the Application Pool) and set all various host headers I need.  Finally it will grant my WebDeploy user rights to deploy to the site.  I'll put a version of that script up in a future post.

On the same project we've used Powershell and the Amazon Web Services .NET SDK to provide tooling for use to push database backups from SQL Server to S3 (what, no RDS yet for SQL Server????)  That's another trick - you get full access to .NET in Powershell simply by pulling in a reference to the right .Net assembly.

Anyway, I could bang on about why you need to learn Powershell if you haven't, but I'll pick up this thread in a future post when I provide a sample script for setting up IIS sites.

On a side note I read about the death of Adam Yauch (MCA) from the Beastie Boys on May 4th - he'd been battling cancer for the last three years and most certainly didn't deserve to put down the mic at 47.  This one's for him.