When it comes to learning PowerShell, everyone fills fear in themselves on How to get those commands in their minds?
You have heard your teachers said to you; Don’t memorize anything, because tomorrow you will forget them. Yes, the same point is here, don’t memorize any command. There is a trick to get all the commands in your mind, in fact, that is no need to take them in your mind because they are located in the PowerShell, and that is known as Help System of PowerShell.
A lot of people thinks, that the only thing that PowerShell can is Cmdlets. No that is wrong because PowerShell can run four types of Commands:
- Windows Native Commands.
Here are 10 examples for each command, except for Script. For the script, those are the extensions that PowerShell can support.
|Windows Native Commands||Aliases||Script||Cmdlets|
|Notepad||Clc||.ps1xml (XML Document)||Get-Process|
|calc||Cls||.psc1 (Console File)||Get-Service|
|Mspaint||gal||.psd1 (Data File)||Clear host|
|Appwiz.cpl||Cp||.psm1 (Script Module)||Child-item|
|Diskmgmt.msc||Del||.pssc (Session Configuration File)||Get-History|
|Devmgmt.msc||Dir||.cdxml (Cmdlet Definition XML Document)||Get-Help|
Aliases: Aliases are the short form of a command like cls means clear host, clc means clear content. To get list of complete aliases type get-alias and press enter.
If you want to find out definitions of those aliases on examples section, just type this command:
Cmdlets have a unique structure of verb-noun for itself. See those examples, one of them is a noun and the other is a verb. Here is a small list of the Verbs that PowerShell can support.
Note 2: If you want to get the list of all the verbs that PowerShell can support, type down Get-Verb and Press enter.
Discovering Microsoft PowerShell Commands
I had told you, Don’t memorize any command instead keep in mind one these help commands.
Help Commands in PowerShell:
Difference Between Help Commands:
Get-Help: It brings all the guides at once.
Help: Which is the old DOS version Help command, it brings all the Information page by page or line by line.
Man: Which is the Unix Version Help Command, it also brings all the Information page by page or line by line.
Note: If you are working with Help and Man cmdlets “Enter Key” or “Enter Button” on the keyboard will bring the Information line by line but “Space Key” or “Space Button” on the Keyboard will bring all the Information Page by Page.
Practice with these examples:
|Get-Help Start-Process||Help Start-Process||Man Start-Process|
|Get-Help Get History||Help Get History||Man Get History|
|Get-Help Get-Service||Help Get-Service||Man Get-Service|
|Get-Help Get-Command||Help Get-Command||Man Get-Command|
|Get-Help Get-Partition||Help Get-Partition||Man Get-Partition|
Note: Get-Help can also bring all the Help which you need without any parameters after.
Let’s work with Get-Process Command:
If I type Get-Process, it will show me a list of the current Processes which are running.
If I type Get-Help Get-Process, it will show me a list of guides for this command.
Notice that the help system’s information has been divided into,
- Name: It shows the command name, if you are using aliases it will help you most.
- Synopsis: It tells you what this command can do.
- Syntax: Syntax is the set of rules, principles, and processes that govern the structure of sentences in a given language, specifically word order and punctuation.
- Description: It explains more about this command.
- Related links: It tells you here are the related commands and links that can help you.
- Remarks: Remarks can be called Help Options because it said if you want to see examples about this command, type Get-Help Get-Process –examples, it also said if you want more information about this command type Get-Help Get-Process –detailed, and also it has said to view the complete technical information about this command type Get-Help Get-Process –full, and finally if you are in PowerShell 2 or Older you can use this command: Get-Help Get-Process –online
Note 1: Get-Help Get-Process –online, now, this command does not have much usage because it was for version 2 and older versions of PowerShell. Instead in PowerShell v5 you can update the complete help system by this command: Update-Help
Note 2: if you are working along with me, you must update the help system, otherwise you can’t find many of the information in the Help like Examples, long description, related links and some others feature. So type down this update-help and press enter.
Let’s try Get-Help Get-Process –detailed. This time you can see even more information about this command like:
- Parameters: Parameter is a rule or limit that controls what something is or how something should be done. It has explained every single piece of information from syntax.
- Examples with Detailed Explanation: There are 11 examples with a completed explanation.
Note: If it is hard for you to read the PowerShell guides, you can open those guides into another window by typing this command: Get-Help Get-Process –showwindow.
I have searched for examples in the search field in the –showwindow and the help windows has highlighted that.
I have created examples of Get-Process in a .txt file.
Summary of Help Options:
You can use these commands for getting Help:
- Get-Help Get-Process
- Get-Help Get-Process –Detailed
- Get-Help Get-Process –Full
- Get-Help Get-Process –Examples
- Get-Help Get-Process –Showwindow
- Get-Help Get-Process –online
Syntax is the set of rules, principles, and processes that govern the structure of sentences in a given language, specifically word order and punctuation. The most important part of Discovering a cmdlet is syntax and Parameters. Let’s learn it with typing this Command:
On the screenshot you can see there is 3 syntax for Get-Service Command. It means this command can be used in 3 different ways. Differences between these are:
- Syntax 1: It has a unique argument of -Displayname
- Syntax2: It has a unique argument of [-InputObject <servicecontroller>]
- Syntax 3: It has a unique argument of [-Name]
Practice with these examples:
- Whenever you see <String> After Parameters, it means it takes arguments.
- Angel Brackets (<>) means it means it takes arguments.
- String means it takes Alpha Numeric string.
- Square Brackets () means it take more than one argument separated by a comma.
Type Get-Service, After that you can see a list of available services on your system. Those shortcut names are called Alpha Numeric string.
Then type; Get-Service -Name BITS and press enter. After that, you can see that service is running.
Let’s Put Multiple Arguments. Get-Service -Name BITS, BFE,Appinfo and press enter.
Take a look at this; Get-Service [[-Name] <string>] [-ComputerName <string>]
Those square brackets () which are outside of angle brackets(<>), they are optional, it means as your wish, wheather you put or no.
Example: Get-service BIF,BFE
You have noticed -Display Name on the syntax is without square brackets(), it means if you are using this syntax -DisplayName is Required.
Example: Get-Service -Displayname “App*”