In today's chapter we will be going over "Using the Help System". This may be the most important chapter in the book, at least it was for me. As Don describes it, "If you aren't willing to read PowerShell's help files, you won't be effective with PowerShell". I have to admit that I was guilty of this in my first learning experience with PowerShell, so I promised myself I would do better this time around. You need to fully read everything in these help files and understand the commandlet use. My fellow Month of Luncher Zack said it best when he said "System Administrators are skimmers by trade", and we are, but please READ the help files.
The primary commandlet here is GET-HELP or the alias' Help and Man. This will allow you to view the available help on other commandlets or help topics. You can even Get-Help on the Get-Help commandlet. The Syntax for using the help for the Get-Service commandlet would be Get-Help Get-Service. The Basic help information will show you the Name, Synopsis, Syntax, Description, and any related commandlets or additional help files associated. There are a few parameter options here that are very useful, as well as the ability to use wildcards to assist in the lookup of help articles if you don't know exactly what it is you are looking for.
The first parameter to remember is -Examples. This will show you syntactically correct examples on commandlet use. It will also show you a description of what the typed command is doing.
The second is the -Detailed parameter. This is where things get a little more interesting. Using this parameter shows all the same things as shown when just using the Get-Help commandlet but also gives you all of the available parameters for the commandlet and their descriptions and use.
The Third is the -Full parameter. This will show you all of the information that is contained in the help file.
Something important to note here for people just starting out with PowerShell or who have very limited experience with scripting (This took me a while to understand). Not all Parameters can be used with each other (Duh!). This is due to commandlets having Parameter Sets. When using the Get-Help command you will see the Syntax section of the help file, and it may contain two, three, or more instances of the commandlet. An example from Get-Service:
Get-Service [[-Name] <string[]>] [-ComputerName <string[]>] [-DependentServices] [-Exclude <string[]>] [-Include <string[]>] [-RequiredServices] [<CommonParameters>]
Get-Service -DisplayName <string[]> [-ComputerName <string[]>] [-DependentServices] [-Exclude <string[]>] [-Include <string[]>] [-RequiredServices] [<CommonParameters>]
Get-Service [-InputObject <ServiceController[]>] [-ComputerName <string[]>] [-DependentServices] [-Exclude <string[ ]>] [-Include <string[]>] [-RequiredServices] [<CommonParameters>]
These show the Parameter Sets or what parameters can be used together. This can save you hours of trying to figure out what is wrong with your syntax.
However, the use of wildcards is what I believe makes this a very powerful learning tool for PowerShell. A simple asterisk or two can help you look up all commandlets associated with process' (get-help *process*), or allow you find the about_help files (get-help about*). The Get-Help even searches the text of the help files and with the help of the wildcards you can find just about anything (example from the book: Get-Help *Breaking*). You can read more about wildcards in the About_Wildcards help.
I challenge anyone reading this who doesn't already use the help to do so. This will make the learning curve much shallower and it is built-in. You can't beat FREE help. There are also some other ways to view the help files including IPad\IPhone Apps, Android Apps, the downloadable online help files from Microsoft (CHM files), TechNet articles, as well as scripts that construct help file graphical browsers (http://mng.bz/5w8e) from the available help files in PowerShell.
No comments:
Post a Comment