PowerShell 1st Cmdletment: Get-Help

I started playing around with PowerShell around v3.0, so in the grand scheme of things, I’m a noob. If you’re new to PowerShell, then welcome to a whole new way of doing things. It’s a great tool which can build greater tools! One of the best things about PowerShell is the PowerShell community and one of my first lessons I learned in PowerShell, which is, the ability to get-help. Help both digitally, through the help system, and carbon based (humans), through online forums, summits, Twitter, peers, etc.

Almost every PowerShell book you pick up explores how to use the PowerShell help system in the first 3 chapters. @jsnover -the Godfather of PowerShell, professes his favorite command is get-help. This command, with the various parameters, gives you the ability to truly learn PowerShell without purchasing a single book. Is it enough to make you a PowerShell ninja? Probably not, although the About_ files are excellent resources themselves.  I’ve dabbled in the Linux BASH environment and loved it, however, felt it was very cryptic and you had to have a working knowledge of the Linux environment and the Man pages could be a challenge. PowerShell, on the other hand, was designed to be intuitive and “discoverable” as a shell environment.  The verb-noun structure of cmdlets allow a “somewhat” IT savvy person (or someone with a limited IT vocabulary) to find commands easily based on keywords (see below get-command examples).

Updating Your Help

As you begin to explore PowerShell, I encourage you to dive right into the help system. First things first, we need to update our help files. Hmm….I wonder if there’s a cmdlet that can help us update our help. Let’ think about our verb-noun structure and discover our cmdlets. I see update and I see help. We can “discover” commands easy enough with our get-command cmdlet. And yes, it does allow for wildcards (*).

update

Conversely, you could search for *help*, and it would return a smaller sample set. This simply demonstrates how you can easily discover cmdlets to accomplish your tasks. As you get familiar with the PowerShell verbs, this will become a great deal easier. The nouns are the meat and potatoes of your discovery.

Let’s update our help with the new cmdlet we found. BUT WAIT! We should probably take a peak at syntax of this cmdlet, well for now, we’ll bypass that and look at some other cmdlets. First, you must have an administrative PowerShell session open (PowerShell needs access to the system32 folder to update help files). You can accomplish this by right clicking on the PowerShell icon and viola, Run As Administrator is displayed. Next, we simply type update-help (see below).

updatehelp

Getting Help

Next, we will investigate the help information for get-childitem. We can access this by typing get-help get-childitem (see below).helpgci.PNG

The parameter set may look daunting (all the options after get-childitem), but once you can decipher a few things, it will be a helluva lot easier. First, after the cmdlet, get-childitem, you will see a bunch of words with a dash (-) preceding them. These are parameters. The old command-option-argument could be use to describe the syntax where the parameter is the “option” and the value to the parameter would be the “argument”. The other items you may notice are the square brackets [].

parameter

These have a few different meanings. You will notice brackets encapsulating the entire parameter and value (above). This implies this parameter is optional. You will also notice some parameter names ([-Path]) are encapsulated with brackets. This signifies the parameter name is optional as well, meaning you can simply provide the value. The other brackets you will see are simply the empty brackets [] (<string[]>). This denotes an array or list of values can be provided. You may also notice this cmdlet does not have a required parameter. All parameters are enclosed in brackets, therefore are optional. Think of it this way, get-childitem has an alias of dir (old command prompt do view a directory listing), can you simply type dir at the prompt and get output? Yes! Same here!

gci

And another example providing multiple values.

gcimultiple

Some other methods to access additional help.

get-help get-childitem #syntax/parameter set of cmdlet
get-help get-childitem -full #syntax, parameter definitions and examples
get-help get-childitem -examples #examples of the update-help cmdlet
get-command *help* #displays cmdlets with the word "help" in the cmdlet

Automation has changed the landscape in IT and PowerShell is a key ingredient. PowerShell is a critical component to the Dev-Ops community and is a valuable skillset in HIGH demand. It’s a fun environment to play in and is something that I cannot stress enough to my students. All it takes is a little commitment and forcing yourself to play in that sandbox and before you know it, you can impress your IT friends on your PowerShell-Fu skills.

Advertisements

One thought on “PowerShell 1st Cmdletment: Get-Help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s