An Omega Geek's Guide to Learning PowerShell
In the last 12 months we've been doing quite a lot of DevOps projects helping teams setup Continuous Delivery processes. One of the tenets of Continuous Delivery is "Automate Everything" – which has been a core part of my "work smarter, not harder" ethic for a number of years. The technology that we've been using to do this work is one of the hidden gems of the Microsoft Platform – PowerShell. It amazed me that a technology that is over 6 years old still doesn't seem to have mass adoption within the Microsoft Development Community. While the Alpha Geeks are frothing at the mouth over new tech such as Node / HTML 5 / WinRT, I really hope that more Omega Geeks will do themselves a great favour and start to learn PowerShell.
I've spent more of the last year working inside PowerGUI than Visual Studio and I've tried hard to take a few of our customers on the learning journey too. I'm very pleased that after doing a quick brown bag session about PowerShell and knocking up a sample framework that one of the DevOps folks took it and ran with it – automating the provisioning of their internal development, test and production environments – from a series of thick word documents that took over 2 man days to work through (and were also horrifically prone to human error) to a series of PowerShell scripts that could automatically provision an environment within a couple of hours.
Thankfully there are a myriad of resources to help you learn PowerShell here are a select that I've found very useful:
Free Guides
If you really want to get your head around what comes out of the box in PowerShell 2.0 (which is installed by default on Windows 7 and Windows Server 2008) a great place to start is Jonathan Medd's – PowerShell 2 – One Cmdlet at a Time – which does exactly what it says on the tin – it lists every cmdlet (think function) and tells you what it does and how to use it.
One of the least known and most powerful features in PowerShell is remoting – the ability to execute PowerShell scripts, in context on a remote machine. This opens so many doors from a DevOps perspective. On the downside – because remoting requires you to deal with networks and security – it can be a bit painful to get up and running with and another indispensible guide is Ravikanth Chaganti's - Layman's Guide to PowerShell 2.0 remoting – to tell the truth – I felt bad reading this free guide – the amount of real world knowledge and blood, sweat and tears problem solving is of such a high quality that it really shouldn't be a free ebook.
Books
The two free guides really wet my appetite and I wanted more – both depth and breadth and I found this in abundance in Bruce Payette's – PowerShell in Action 2nd Edition – if you want a holistic view of the platform – it's a great start. If you want a more practical guide to how to use PowerShell there are two other great resources – first is Don Jones and his book Learn Windows PowerShell in a Month of Lunches. Don is a bit of a star he's very active not only on his twitter account – but he's also produced a seriously large number of accompanying screencasts, freely available on YouTube. The second is Lee Holmes (who's been on the PowerShell team from the start), his book The PowerShell Cookbook is a wonderful resource – brimming with Problem –> Solution recipes; if you're getting started with PowerShell these are the type of problems you are going to hit straight away and such The PowerShell Cookbook should be your first port of call. The latest PowerShell book I've been reading is PowerShell and WMI by Richard Siddaway which is a little more advanced and hard-core – but useful for those of us who want to interact with Windows Machines at a lower level.
Blogs & People
As always the first place for a Microsoft Technology is the Official Microsoft PowerShell Blog. Next would be the man behind PowerShell, Microsoft Distinguished Engineer and Lead Architect for the Windows Server Division – Jeffery Snover, his enthusiasm for PowerShell and being more productive with automation is utterly infectious – he's a really great speaker and I would highly recommend watching his talks (listed below). After Jeffery the next stop is Lee Holmes' blog. When you get stuck and start searching for help – chances are you'll land on Joel Bennett's Huddled Masses blog – lots of great pragmatic content to be devoured there. Another great resource is the PowerShell Community Site.
Web Casts
If you don't have time to read books luckily Microsoft have put a lot of effort promoting PowerShell at their various conferences and via Channel9. I can't recommend these talks highly enough – the topics are wide and varied – from using PowerShell to manage servers, to using PowerShell to create a management API over your applications – each of the talk shows how flexible PowerShell is and how productive you can be with it.
Channel 9
- Jeffrey Snover & Bruce Payette (2007) - Windows PowerShell: Origin and Future
- Jeffrey Snover and Dmitry Sotnikov (2007) - Learn and Master Windows PowerShell with Quest Software's PowerGui
- Expert to Expert (2008) - Erik Meijer and Jeffrey Snover - Inside PowerShell
PDC 2008
- Jeffrey Snover - PowerShell: Creating Manageable Web Services
PDC 2009
- Kenneth Hansen, Narayanan Lakshmanan - Building Your Administration GUI over Windows PowerShell & Windows PowerShell: An Automation Toolbox for Building Solutions That Span Small Businesses, Enterprises, and Cloud Services
Tech-Ed 2010
- Mir Rosenberg, Refaat Issa - Advanced Automation Using Windows PowerShell 2.0
- Jeffery Hicks - Paradigm Shift: Microsoft Visual Basic Scripting Edition to Windows PowerShell
- Phil Pennington, Don Jones - Manage Your Enterprise from a Single Seat: Windows PowerShell Remoting
- Don Jones - Inventory Your Network and Clients with Windows PowerShell
Build 2011
- Andrew Mason & Jeffery Snover - Windows Server 8 apps must run without a GUI - learn more now
- Jeffrey Snover, Refaat Issa - Make your product manageable & Manage a highly-efficient environment at scale using the Windows Management Framework (WMF)
- Christopher Palmer - Windows networking with PowerShell: A foundation for data center management
Tech-Ed 2011
- Dean Corcoran - PowerShell Above and Beyond: GUIs, Workflows, and More
- Don Jones - Windows PowerShell Remoting: Definitely NOT Just for Servers
- Dan Harman, Jeffrey Snover - Advanced Automation Using Windows PowerShell 2.0
- Jeffery Hicks - Managing the Registry with Windows PowerShell 2.0
- Jeffrey Snover - Windows PowerShell for Beginners
Writing testable scripts
One of the most immature aspects of the PowerShell platform is writing tests for scripts – I've tried many of the frameworks that are out there – each has it's own strengths and weaknesses – but the framework I've been using (with some success) of late is Pester – a BDD style framework for PowerShell, you can grab the code from the official GitHub Repository.
Tooling
Lastly a word on tooling – even though Windows comes with PowerShell ISE (Integrated Scripting Environment) – I've found PowerGui to be a much nicer environment to work in – the debugging support (which you will need) is far superior to ISE.
Remember: work smarter, not harder!