Understanding the 'Get-Help' Command in PowerShell (with examples)
- Windows
- December 17, 2024
The Get-Help
command is an essential component of PowerShell, designed to provide users with detailed help information and documentation for PowerShell commands, including aliases, cmdlets, and functions. This command acts as a comprehensive manual, offering insights into command usage, parameters, examples, and detailed documentation. For more advanced users, it can facilitate deeper exploration into PowerShell’s functionalities and capabilities.
Use case 1: Display general help information for a specific PowerShell command
Code:
Get-Help command
Motivation: When you first come across a PowerShell command and want to get a basic understanding of its functionality, usage, and purpose, using Get-Help
without any additional flags is a quick and straightforward way to retrieve essential information about the command.
Explanation: The command
in this context is a placeholder for any PowerShell command you wish to explore. By entering the command you’re interested in, Get-Help
fetches a synopsis, basic usage guidelines, and general information about the command and its purpose.
Example output: When you use Get-Help Get-Process
, the output will include a general description such as:
NAME
Get-Process
SYNOPSIS
Gets the processes that are running on the local computer or a remote computer.
SYNTAX
Get-Process [[-Name] <String[]>] ...
Use case 2: Display more detailed documentation for a specific PowerShell command
Code:
Get-Help command -Detailed
Motivation: When the basic command information isn’t sufficient, and you need a deeper understanding, including details on input, output, and a broader overview, -Detailed
is the flag to use. It provides expanded documentation that includes richer knowledge about the command’s usage scenarios.
Explanation: The -Detailed
argument expands the general help documentation, typically including more in-depth descriptions of the command’s parameters, input types, return types, and often additional notes that might not be immediately visible with the basic Get-Help
usage.
Example output: Using Get-Help Get-Process -Detailed
could extend the output to include:
DESCRIPTION
The Get-Process cmdlet gets the processes on a local or remote computer...
PARAMETERS
-Name <String[]>
Specifies the process names of the processes to be retrieved.
Use case 3: Display the full technical documentation for a specific PowerShell command
Code:
Get-Help command -Full
Motivation: The -Full
argument is for users who require the most exhaustive amount of information available for a command. This includes every piece of documentation possibly recognized by the help system, ensuring no detail is left out.
Explanation: The -Full
argument is the master switch for documentation detail in PowerShell. When specified, it lists every relevant detail about a command including examples, extensive descriptions, all parameter options, and any additional notes.
Example output: Get-Help Get-Process -Full
may output:
NAME
Get-Process
SYNOPSIS
Gets the processes that are running on the local computer or a remote computer.
DESCRIPTION
Detailed description...
EXAMPLES
Example 1: Get all processes
RELATED LINKS
Online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-process
Use case 4: Print only the documentation for a specific parameter of a PowerShell command
Code:
Get-Help command -Parameter parameter
Motivation: When you’re focusing on a specific parameter of a command and want minimal distraction from other documentation details, retrieving specific parameter information helps streamline the learning process.
Explanation: The command -Parameter
can be followed by a specific parameter name. If you wish to see information about all parameters, using *
will list them all. This approach isolates the documentation to just what’s needed, facilitating faster and more accurate scripting and command usage.
Example output: When executing Get-Help Get-Process -Parameter Name
, you can expect:
-Name <String[]>
Specifies the process names of the processes to be retrieved.
Use case 5: Print only the examples of the cmdlet
Code:
Get-Help command -Examples
Motivation: Code examples are often the fastest way to understand how a cmdlet is intended to be used in practice. If you’re someone who learns better with concrete examples rather than abstract definitions, this flag is immensely useful.
Explanation: Here, -Examples
is used to narrow down the extensive documentation to only the example section, which demonstrates practical applications of the command.
Example output: Executing Get-Help Get-Process -Examples
yields:
Example 1: Get all processes
PS C:\> Get-Process
Use case 6: List all available cmdlet help pages
Code:
Get-Help *
Motivation: This command allows users to explore the range of cmdlets available in PowerShell. It’s particularly useful for new users or those looking for additional PowerShell features they might not yet be aware of.
Explanation: The asterisk *
acts as a wildcard, prompting PowerShell to return a list of all cmdlets and their brief descriptions, giving users a broad overview of what’s available.
Example output: A few lines of example output include:
Name Category Synopsis
---- -------- --------
Add-Content Cmdlet Adds content to the specified items...
Clear-Content Cmdlet Deletes the content of specified items...
Use case 7: Update the current help and documentation knowledge base
Code:
Update-Help
Motivation: PowerShell is frequently updated, and with each update comes revisions and improvements in functionality and documentation. Keeping your help system updated ensures that you have the latest information, bug fixes, and examples.
Explanation: Update-Help
downloads the newest help files for the version of PowerShell you’re using, replacing outdated information with the most current data. This is crucial for staying current with PowerShell developments.
Example output: Running this command might return:
Starting update of Windows PowerShell help...
Finished updating help for the specified modules.
Use case 8: View an online version of PowerShell command documentation
Code:
Get-Help command -Online
Motivation: Sometimes, the local documentation might not have everything you need, or you may want to view documentation in a more visual format, like a web browser. This command extends your search for knowledge beyond your local machine.
Explanation: The -Online
switch generates a link to the official Microsoft documentation page for the command, opening it in the default web browser, where you have access to the most detailed and comprehensive resources available.
Example output: A browser window will open with a page similar to:
Navigating to https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-process
Conclusion:
The Get-Help
command in PowerShell is more than just a basic guide; it’s an in-depth, dynamic resource for mastering PowerShell commands. By understanding its diverse use cases, users can both learn about new functionalities and maximize their efficiency in using PowerShell, ensuring productive and effective use of the tool in daily operations. Whether you’re new to PowerShell or an expert, continually utilizing Get-Help
is essential for keeping your scripts both powerful and precise.