Basic syntax and commands in Windows Powershell

You should know below things in Windows Powershell.

  1. Windows Powershell commands are not case-sensitive ( Remember that in Linux commands are case sensitive.
  2. All commands in old windows command prompt can be executed in Powershell.

Checking version of Powershell

To check version of Windows Powershell, you can use below command.

> echo $PSVersionTable

powershell-version

powershell-version

Getting help

To get help on everything, you can execute below command.
> get-help *

Above command displays help terms from various categories like alias, Cmdlet, function, HelpFile.

To get the help on all command lets
get-help -Category cmdlet

To get the help on all functions
get-help -Category function

To get the help on all providers
get-help -Category provider

To get the help on all Help Files
get-help -Category helpfile

We can also use below command (Alias – gcm) to show the list of commands and functions.

> Get-Command

To display commands with specific name say xyz
> Get-Command *xyz*

“Get-Command” also allows you to search the commands using nouns or verbs.

> Get-Command -noun Job
To get examples and full information about specific command, you can use below syntax.

  1. get-help <command-name> -online
  2. get-help <command-name> -full
  3. get-help <command-name> -examples

To update the help, you can use below command.
> update-help

To get the list of all verbs, you can use below command.

> Get-Verb

Understanding command syntax

“Get-Help” command shows the syntax of command. Looking at the syntax, we can figure out what parameters are positional, optional etc. It also shows the aliases for the command.

powershell-command-syntax

powershell-command-syntax

As you can see in above image, there are many variations of Get-Process command. Anything in the [] is optional. <string[]> means that parameter takes array of strings.

Also note that in the end it is saying [<commonParameters>]. Usually all commands can accept common parameters.

Here is the list of common parameters.

  1. verbose
  2. debug
  3. WarningAction
  4. ErrorAction
  5. ErrorVariable

To clear the screen, you can use “clear” command (Just like in Linux).

You should also know some of the Powershell extensions.

  1. .ps1 – Powershell script file
  2. .psd1 – data file
  3. .psm1 – Powershell Script module

Tips and tricks

  1. You do not need to type complete command at the command prompt. You just need to type first few characters and Powershell completes it for you. For example instead of typing “Get-Process”, you can type “Get-Pro” only and then press TAB key. Same applies to the parameters of the command as well

You may also like...