PowerShell Get-Help Cmdlet
My goal on this page is to explain Get-Help's hidden but useful nuances.
The examples are designed to help intermediate scripters delve deeper into PowerShell's capabilities.
Windows PowerShell Get-Help Topics
PowerShell Cmdlet Litmus Test
Amateurs: Use Get-Help to get an overview of what a
In this example we just use Get-Eventlog as a vehicle for learning about Get-Help.
# Typing this cmdlet on its own results in an error
The problem, Get-Eventlog is asking us for an input (LogName). Suppose we don't know the precise logname? Let us call for:
# Cmdlet help with examples
-- But Get-Eventlog also has a second usage --
Get-EventLog [-AsString [<SwitchParameter>]] [-ComputerName <String>] [-List [<SwitchParameter>]] [<CommonParameters>]
# Get a list of available logs
LEM will alert you to problems such as when a key application on a particular server is unavailable. It can also detect when services have stopped, or if there is a network latency problem. Perhaps this log and event management tool's most interesting ability is to take corrective action, for example by restarting services, or isolating the source of a maleware attack.
Yet perhaps the killer reason why people use LEM is for its compliance capability, with a little help from you, it will ensure that your organization complies with industry standards such as CISP or FERPA. LEM is a really smart application that can make correlations between data in different logs, then use its built-in logic to take corrective action, to restart services, or thwart potential security breaches - give LEM a whirl.
Parameters (Also Called Arguments or Switches)
The reason you called for help is probably to check the names of the parameters. Once I show you what to look for, it only takes a few extra seconds to scan a parameter's attributes, and this knowledge gleaned from Get-Help could save you 10 minutes of fruitless scripting.
Our Vehicle is Get-Help Get-Eventlog.
-After <DateTime> At first glance you probably overlooked the <Type> definition in brackets, but now in future you will absorb this extra information.
In this example, knowing that -After expects <DateTime> will alert you to researching the format, especially if you get an error. Get-Date may give you clues whether to use dd/mm/yy or mm/dd/yy.
-ComputerName <String> Clearly this indicates a parameter that accepts names such as BigServer, subtely, the square brackets tells you that you could type multiple names separated by commas. -ComputerName [BigServer, LittleServer]
-List [<SwitchParameter>] This is a tricky 'Type' to understand at first. At it's simplest <SwitchParameter> means the value for this parameter is 'false', unless you explicitly set a value.
-Newest <Int32> Means a number!
Not all attibutes will have useful or interesting information, but there is usually one item that gives you ideas for using the underling cmdlet more effectively.
Accept Pipeline Input
Pipeling (|) is PowerShell's signature tune. You may have used $_. to denote 'in this pipeline'. In a nutshell, if 'Accept pipeline input is true', pipeling will work with this parameter.
There are two options for pipeline input, ByPropertyName means it will accept all PowerShell objects, whereas, ByValue means that it will only accept integers as used by -ID parameters.
# PowerShell script to list parameters with ByPropertyName
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Once you find PowerShell v 3.0 on your computer, before you do anything else, you need to run the Update-Help cmdlet. What this does is populate, then refresh the local cmdlets' functions and concept help files.
Should You Use Plain Help or Get-Help?
The rule is if the script is only for your eyes suit yourself, but if colleagues are involved then avoid all PowerShell aliases and use the full cmdlet. Incidentally, Get-Help has it's own parameters and I always append -full to see Microsoft's examples for a particular cmdlet.
Conceptual topics begin with 'About_xya. For instance, About_Foreach displays information about constructing loops.
Summary of PowerShell's Get-Help
Instead of using Get-Help merely to list the parameters. I want show you how studying the attributes can teach you the principles behind PowerShell. For instance, pipelining and objects. Knowledge of a parameter's properties will also help you write tighter code.
If you like this page then please share it with your friends
See more Microsoft PowerShell tutorials
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.