Basic syntax and commands in Windows Powershell
You should know below things in Windows Powershell.
- Windows Powershell commands are not case-sensitive ( Remember that in Linux commands are case sensitive.
- 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
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.
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.
- get-help <command-name> -online
- get-help <command-name> -full
- get-help <command-name> -examples
To update the help, you can use below command.
To get the list of all verbs, you can use below command.
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.
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.
To clear the screen, you can use “clear” command (Just like in Linux).
You should also know some of the Powershell extensions.
- .ps1 – Powershell script file
- .psd1 – data file
- .psm1 – Powershell Script module
Tips and tricks
- 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