Windows Powershell Tutorials – Discovering Commands and Using Help

When you start learning powershell you wont be knowing all the commands. So the help system will let you discover the commands and gives you a short note about what a particular command does. By using help you can avoid lots ans lots of errors and you can save time in the learning process.

The first thing you have to do is update the help system. You can update the help system using the following command.

update-help

The above command will update all the help files associated with powershell.

Getting Started:
If you want to know what are the options available for a particular command Update-Help will do the work. Let say , you want to know about update-help command. Issue the following command in the powershell window to get a detailed information about the Update-Help command.

Help update-help -full

If you want to see the results in a separate window, where you can search for a particular string, use the following command.

help update-help -ShowWindow

Discovering Commands:
As you start learning , you wouldnt be aware of most of the commands. So lets say , you want to know the command which shows you all the details about ipadress. Powershell has a great way to discover command using help. Poweshell supports wildcard search. The following command will search for the commands which has the ipaddress string attached to it.

help  *ipaddress*

The above command will list out all the commands which includes ipaddress. From that you can get the command which shows you all the ipaddress details. In this case it is Get-NetIpAddress

Using Help:
Now you know how to discover a command and the next thing you have to learn is that what and all parameters and values you can pass to the particular command. You can find that using the help command. The following command will show you the details and syntax of the Get-Service command.

help Get-Service

The syntax section in the help will show you how to use the command. In the help section of Get-Service command , syntax looks like the following image.

If you look at the image above, there are three ways you can use the Get-Service command. The strings which start with are parameters and <string[]> means values which you pass to the command. The two square brackets which are jammed one against each other means that you can pass multiple values with the command. The commands within square brackets are not mandatory, which means you can run the Get-Service all by itself and it return all the available services.

-Name is a positioned parameter in Get-Service command, which mean if you pass a value with Get-Service method with or without the -Name Parameter, it will give the same output. Its because , powershell automatically adds the positioned parameter to the value. Int this case -Name parameter is positioned first. For example, the following two commands will give the same output.

Get-Service -Name winrm
Get-Service winrm


Changing the error color:
When ever you get an error , it will be shown in red color. There is a simple command which changes the error color if you don’t like red. The following command will change the error color from red to green.

$host.Privatedata.ErrorForeGroundColor = 'green'
$host.Privatedata.ErrorBackGroundColor = 'black'
 

Other Interesting Blogs

Leave a Comment

Share via
Copy link
Powered by Social Snap