Get-Help – the PowerShell Way

 Feb 25, 2014

Some of you may have noticed in a number of my previous blogs that I am a big fan of PowerShell and you are right. I have followed PowerShell from its early days of the mid 2000’s when it was known as Monad up until now, where it's commonly known as PowerShell 4.0 (Server 2012 R2/Windows 8.1).
I find it extremely powerful and efficient, but very intuitive and easy to understand at the same time. Now don’t get me wrong - I am not a developer, I am an infrastructure guy. Hence, the mysteries of C# and to a great extent, VB scripting, will probably always remain a mystery to me, but I can’t help be impressed with PowerShell’s simplicity. For example, if you want to find out details about services running on your server then you can use the Get-service cmdlet, or if you want to configure the networking parameters of your network card then you use can the Set-NetAdapter cmdlet. PowerShell was designed right from the very beginning to be a Server Administrator tool, not a generic programmer’s language. Since PowerShell does use a lot of the logical principles of programming languages in general, and it is based upon the .NET Framework (i.e. it is object based so when I tell it to 'Get-Service,' it gets ALL the properties of ALL of the relevant services), I am quite happy to let the developers have their own kind of fun with things like the function cmdlet, but I still find the syntax to be very straight forward and logical. The other great thing I like about PowerShell of course is all of the great help features built into PowerShell. There are quite a lot of them, so allow me to do a memory dump and list the main ones that I use. Before I begin though, please remember the basic PowerShell syntax of verb-noun – and the noun is always singular.

Get-Help Cmdlet

We can’t help (pun intended) but start with the Get-Help cmdlet. This is a command that you will find yourself using on a daily basis to find out information such as what a particular cmdlet does, what its syntax options are, examples of that cmdlet’s usage, details of each of the required and/or optional parameters, whether or not that cmdlet has a predefined alias and so on. Just for fun, try the following to find out all about the Get-Help cmdlet and its options:
Get-Help Get-Help –full Get-Help Get-* Get-Help –Get-Service Help
To open 'Online Help' for any cmdlet or function (provided that you have an internet connection), you can add the '–Online' parameter to the end of the cmdlet. PowerShell V3.0 brought in the ability to update the help files from the Internet with the 'Update-Help' cmdlet, along with a cmdlet (Save-Help) that allowed you to save the updates. A very useful way of grabbing the updates on an internet connected machine, for manual transferral to a non-internet connected machine.

Help About

PowerShell also has the ability to download a rather large series of help text files beginning with 'about_'. Since PowerShell 3.0, help files are not downloaded by default, but you can use the following to both update your help files and download the extra about files:
Update-Help –UiCulture “en-us”
The –UICulture parameter allows you to specify your language, and this must be specified to download the 'about_' text files. You can then check the contents of each of these files in the %windir%\System32\WindowsPowerShell\v1.0\en-US location (I am using the English location here), or via a PowerShell cmdlet such as 'Get-Help about_CommonParameters'.

Get-Command cmdlet

This is another cmdlet that lists all of the aliases, which I'll speak about in a moment. Functions and cmdlets available at a particular time hence, it is very useful with the '–Module' parameter to display the cmdlets specific to a particular module.

Get-Help in PowerShell

Aliases

These are also a big help when typing cmdlets as they can considerably reduce typing, but I do hold with the guideline that aliases should only be used when you are typing cmdlets. If you are typing cmdlets for others to read – such as in a script – I suggest that you type the cmdlet in full so that other people can follow the script in an understandable fashion, and particularly if you are using your own “home-grown” aliases. The following is a line that I have used in multiple classes to list all the current aliases and to save them to a file. It can also be easily printed for future reference.
Get-Alias | Format-Table –AutoSize >”C:\Temp\PowerShell Aliases.txt”
The above line worked perfectly fine in PowerShell 2.0, but the output syntax changed slightly in v3.0. I found it easiest to  add the required columns:
Get-Alias | Format-Table –autoSize Name,Definition >”C:\Temp\PowerShell Aliases.txt”

Profiles

PowerShell actually has up to 6 different profiles (dependent upon the version) that you can use to run various cmdlets, set up your own aliases, variables and functions, etc. These profiles are PowerShell scripts, placed in specific locations and having specific names, which allow them to be loaded automatically at the start of a PowerShell session.

Tab Completion Feature

This feature in PowerShell (known as Intellisense in the ISE) has been a huge boon to this fat fingered typist and it is probably my most liked help feature. All I have to type is enough of the cmdlet to make it unique, hit the 'Tab' key and PowerShell will complete the cmdlet. This can save a considerable amount of time typing, and reduces typos by a huge order of magnitude. It is also great for giving the complete cmdlet if you are creating scripts. Even if you don’t type enough to make it completely unique, keep clicking the 'Tab' key and PowerShell will cycle through the options. PowerShell 3.0 also brings in support for Tab completion of service or process names, event log names, module names, hash table keys in functions etc. As you can see there are many ways PowerShell can help you, but what is your favourite “help” feature? Is it one of the above methods or have you found a different method? If you're interested in learning more about PowerShell, take a look at New Horizons' 10961 - Automating Administration with Windows PowerShell v3.0 training program.

How do your Excel skills stack up?   

Test Now  

About the Author:

Gordon Cowser  

With over 22 years real world and training experience, Gordon is our most senior IT Infrastructure trainer. His expertise includes but is not limited to; Microsoft Server and Client OS, Messaging, Collaboration, Active Directory and Network Infrastructure. Gordon also specialises in SharePoint technologies training in both technical and end user aspects. With his extensive skill-set he brings a thorough mentoring capability to the classroom where he can advise on technical issues and challenges often beyond the scope of the course curriculum. A very approachable and experienced training professional, he has the ability to establish credibility fast with students at all levels.

Read full bio
top
Back to top