PS for .NET devs part 1: Getting started with PowerShell

After getting everybody warmed to the idea of learning PowerShell in part 0 of this series. Let's dig into a couple of ways to get started with PowerShell.

The resource list

By now PowerShell has gained so much traction at this moment that I could probably fill several dozen pages with links, pointers to the excellent resources available on-line or in print. However I will refrain myself to a couple starting points.

On-line resources

  • PowerShell Community Toolbar This is a browser plug-in that aggregates a big set of resources, from download links to the various PowerShell releases to a huge list of blogs filled with PowerShell content, to the localized PowerShell on-line help. Even if you are not very fond of browser toolbars I suggest you install it, take some time to follow the various links save them and uninstall the toolbar.
  • ScriptCenter PowerShell homepage this contains loads of resources to get you started and should be considered the canonical starting point for finding PowerShell related resources.
  • Windows PowerShell Survival guide A large list of resources to get you started, compiled by the community.
  • PowerScripting podcast If you have some time during you commute or any other activity that allows you to listen to some audio I highly recommend this show. The show notes are of a great quality, and contain lots of links to learning resources. The first shows take you step by step through the process of learning PowerShell.

(e-)Books

Just use PowerShell instead of cmd

When learning something new it is always nice to be able to start with something familiar. The beauty of PowerShell is that all your previous knowledge about your favorite command-line tools are not lost. PowerShell is a shell which means you can use it to start any of tool you used to start in cmd. Moreover the PowerShell team has incorporated a large number of aliases that should be familiar to you whether you are coming from a linux or cmd background the commands you know like dir, ls, cd, del, rm all work as you would expect. These aliases are also very handy for those who don't like to type long commands at the prompt. To get an idea of what aliases are available try the following:

Using PowerShell as your preferred shell gives you the opportunity to gradually learn PowerShell and just lookup/research stuff as you use it in your day to day work.

The 3 amigo's of discovery

When learning PowerShell I've found that the most helpful and best Cmdlets are the following three.

Get-Help

Get-Help does exactly what you would expect especially when you know it's aliases: man, help. You can get the help on help by typing help at the prompt. This shows you how you can use Get-Help. Note that PowerShell also comes with topical help pages that start with about_ to get an overview of the available topics type:

at the PowerShell prompt.

Get-Command

Get-Command provides a way to search for a Cmdlet you would like to use. Looking at the output of help Get-Command or shorter Get-Command -? you will see that one of the parameter sets contain the -Noun and -Verb parameters. The naming convention used for Cmdlets is <Verb>-<Noun> this makes remembering and searching the Cmdlets a lot easier. Say for instance I would like to know all Cmdlets that remove stuff then

will list them nicely. If I would like to know what Cmdlets are available for working with computer objects, I would type:

Get-Member

Get-Member list all member that is public methods and properties of the object passed to it. This ideal for finding what information can be extracted from an object, what you can do with a specific object respectively. To for instance lookup what properties you could use on a file to sort in a directory listing you could type

Or if you don't want to wait on a slowly loading MSDN page to lookup what methods are available to you on a TimeSpan object you could use something like:

Or if you can't remember the way SubString works type:

where gm is the (shorter) alias for Get-Member.

I hope this provides enough pointers to guide you through your first steps to PowerShell mastery. Check back soon for part 2 of this series when we dive in to the PowerShell language as viewed through the eyes of a C# developer.

Wed 22 Jun 2011
References