Last week I was up in Edinburgh with Microsoft presenting at their IT Pro Camps. We had multiple mentions how PowerShell can help you with the managment in the three topic areas we were covering: Hyper-V, Private Clouds and Consumerisation (supporting BYOD scenarios). Taking the audiences for those three days as a representative sample, it looks like about half of the Windows-based IT community still hasn’t begun their PowerShell journey.
Now is a great time to get started with PowerShell, especially with its increased prevalence in Windows Server 2012 and some of the great improvements in PowerShell 3.0. For those just getting started, I’m encouraging everyone to get familiar with the following four cmdlets (pronounced “command-lets”) in particular:
Get-Command finds all the commands (including aliases and functions) that are available to you in the current shell.
Get-Member tells you about the objects on the pipeline which the previous cmdlet has output. eg. Get-Process | Get-Member
Get-Help provides help about cmdlets and features of PowerShell (in v1 and 2 this is all in the box; with PowerShell 3.0, you need to Update-Help).
Get-PSDrive tells you about the drives that PowerShell is exposing; not just the file system, but the registry and others.
Given those four cmdlets, you can get a long way by yourself, just through experimenation. Don’t forget to use the -whatif parameter (or -confirm) on any cmdlet that might change something.
eg. Get-Process | Where {$_.name -match “^s”} | Stop-Process -whatif
In PowerShell 3.0, you can benefit a lot from using the Show-Command UI in the PowerShell ISE (Integrated Scripting Environment) to help you with the parameters required to achieve a task. As a beginner to PowerShell, you can also learn a lot by looking at other people’s scripts; the Microsoft Script Explorer for Windows PowerShell is a useful tool to find scripts and other great resources from online repositories.
There’s no better way to learn PowerShell than to write some scripts that solve real problems, and there are a number of pre-canned problems that you can take a shot at in the Windows PowerShell Scripting Games. You’re too late to enter this year’s competition, but you can still try out the challenges, and once you’ve given it a try, you can see the expert solutions from some of the top members of the PowerShell Community.
I suggest that while you’re getting used to PowerShell, you print a couple of quick reference guides (or cheat sheets) and keep them close to hand, or pinned up beside your monitor. You can also download a great free ebook called Mastering PowerShell from PowerShell.com, where you’ll also find a bunch of other great resources (including another free ebook on PowerShell remoting, for when you’ve got to grips with the basics).
If you like to go and buy a book, then the beginner’s book of choice is Don Jones’ Learn Windows PowerShell in a Month of Lunches.