Even after using the PowerShell language to write scripts and perform the automation, I find it challenging to find exactly what commands I need to use how to use those commands appropriately.
With any other suitable programming language, you will find some built-in help functionality to guide you through the instructions. It may simply describe what the commands are or could be full of example scenarios to get you up and running in no time.
In this article, I’ll cover all the aspects of how to get help from PowerShell’s Get-Help command without even leaving your terminal.
Prerequisites
If you are not familiar with PowerShell commands and syntax, be sure to check out the following article to recap the basics of PowerShell:
If you choose to follow along, you should have a Windows machine with PowerShell already installed, or you can use this article to install the PowerShell.
What is Get-Help in PowerShell
PowerShell Get-Help
cmdlet provides a rich set of information and instruction on any command, function module, or script. The resulting information includes Name, Syntaxes, Alias, and Examples for using the command.
In your terminal, run the command Get-Help
to display the information about what the command is all about.
Review the Examples section that displays the common way you can use the help command to find information using other modules or commands.
Updating PowerShell Help Module
PowerShell uses local storage to save the help information and reference for the commands so that you don’t have to be connected all the time to use the help module.
Before you go further into finding help for modules, it’s best to update the help command as it may not have all the information in the beginning.
- Run the PowerShell in the Admin mode and paste the following command to perform the update for the help module:
- You will see the progress bar for updates:
Using Get-Help in PowerShell
You can run the help command on almost every PowerShell command, provided that the third-party modules include the help resources. The most common way to use the help command is by calling Get-Help
with the name of the command you wish to look up.
One of the typical commands you may use daily is ls
which list your current directory files. Let’s take a look at what the help for the command looks like.
Note: The query for command accepts the wildcard (*) or (?) search, such as
Get-Help Get-*
, which display the list of all the modules that start withGet-
Run the following command in your terminal to list the help for ls
command:
The result will display the output for the command, including the following key heading: Name, Synopsis, Syntax, Description, Related Links, and Remarks.
- Name → Name of the command. In this case,
ls
is an alias/alternate-name for theGet-ChildItem
command in PowerShell. - Synopsis → The intent of the command is displayed to give a brief description of what the command does.
- Syntax →The syntax section covers all the ways you can use the command. If there is more than one use case for any given command, you will see multiple unique syntaxes in this section.
- Description → The detailed usages and information about the command are available in this section.
- Related Links → Related links section include any relevant command or modules that might be useful along with the base command you are searching for.
- Remarks → The final section displays a handful of examples on where else to look for further information on this command. Use this section to get more in-depth information on the modules and commands.
Similarly, you can use a similar search pattern to find the information for almost any command, including the parameters for the specific command in the hierarchy from your PowerShell terminal.
Run the following command in your terminal as an example to get the help for a specific parameter inside the ls
module:
Displaying Examples and Verbose Help in PowerShell
Getting the description and syntax is not the only thing you can do with the Get-Help
module. PowerShell allows you to pass on some additional help parameters to give you more flexibility on the information you see.
Based on the previous command, you can add -examples
flag at the end of the command in your terminal to display examples for the module.
The output will display the set of examples based on various actions available in the queried command.
Similarly, to get the complete set of descriptions, you can use the -full
or -detailed
flag to display the information. If you wish to read all the detailed information in a browser session at any moment, add -online
flag, which will redirect you to the browser on the relevant page for that query.
Conclusion
I hope that gives you an idea of how to query and use the PowerShell Get-Help
command to look up examples and details of any command. Consider leveraging the help command wherever you get stuck and need to dig deeper to learn more about the modules.
Check out the previous article in the series of PowerShell: