How Do I Get-Started With PowerShell?

Commands in PowerShell are called cmdlets (pronounced “command lets”) and they are in the form of singular verb-noun commands like Get-Alias (not Get-Aliases).

In my opinion, there are three cmdlets that are the key to figuring out how to use PowerShell and finding help when you need it. These cmdlets are:

Get-Help (help)
Get-Command (gcm)
Get-Member (gm)

Get-Help or Help for short. Help isn’t actually an alias, but it works exactly the same way if your using the PowerShell ISE. I’ve run help *alias* in the screenshot below:

As you can see in the above screenshot, help doesn’t search for cmdlets, it searches for help topics and while it can help you find cmdlets, its power is in displaying the help topic for a particular cmdlet such as when I run help Get-Help to display the help topic on Get-Help:

You can use the -Detailed, -Examples, -Full, or -Online optional parameters with the help function to display additional information or the online help depending on which one is used.

One of the lesser publicized  parameters that’s useful if you want to know something specific about a particular parameter for a cmdlet is the -Parameter parameter which gives you detailed information about a particular parameter as shown below:

The cmdlet that’s better for searching for actual cmdlets is Get-Command because it has an option in one of its parameter sets for searching for the CommandType of Cmdlet or cmdlets that use certain verbs and/or nouns via its other parameter set. You can’t use both the -CommandType and (-Noun or -Verb) options at the same time since they’re in different parameter sets. There’s also an option to search for cmdlets that a module added.

I specified the -Full parameter in the above command even though you can’t see all of the returned information in the screenshot. It contains very useful information such as whether or not parameters are required, positional, what type of input they accept, etc:

If I’m looking for a cmdlet so I can find out what aliases exist in PowerShell to keep from having to always type out full cmdlet names. I’m going to use Get-Command to search for all cmdlets about aliases. I’m going to use wildcards on each side of the singular noun “alias” since I’m unsure of the actual cmdlet name.

Now that I have the cmdlet name I want to use (Get-Alias), I can get the help topic on it to figure out how to use it:

I want to know if there are any aliases for Get-Command. I’m going to use the -Definition optional parameter with Get-Alias to return the aliases for Get-Command. I’ve piped the results of this command to Format-Table and used the -Autosize parameter to keep the results as narrow as possible for easier viewing on this blog.

I can see that the alias for Get-Command is “gcm” so I can use that alias instead of typing out the full command. If you’re writing a script or providing code to someone else, use the full cmdlet name instead of the alias.

I’ll cover using the -Module optional parameter for Get-Command in my next blog article and the Get-Member cmdlet in a future blog article.

µ

1 Comment

  1. smithmedia79

    Great post Mike! I’m looking forward to trying some of this out in the future.

    Reply

Leave a Reply

%d bloggers like this: