A good starting point in explaining how to use PowerShell is how to use the Help System it provides. The commands i’ll be focusing on are Get-Command and Get-Help
Showing these commands should be a nice primer of how get the hang of writing PowerShell. Lets get into it.
How they work?
I compare Get-Help it to an Instruction Guide and a dictionary combined. It provides descriptions, as well as the syntax, of what commands you are inquiring about. It also can provide examples of how to use the command for a clearer understanding.
Get-Command is best described as an Index of a book. It basically lists what commands exist and what type of command they are. This is nice as you would like to see what commands are available before maybe digging into the syntax. The amount of times i’ve typed commands and had errors come up saying PowerShell doesn’t recognize
I will mention that these systems are constantly being updated. As you can imagine, Microsoft is always trying to innovate with new features and with the importance of PowerShell, they incorporate new commands to configure such features.
I like to provide a few quick ways of how to use both of these commands
Commands
- Update-Help
- Good to run every once in awhile especially if you’re interested in latest features. It will pull new commands and install them on your command to use
- Get-Help <command> or Help <command> <-Full/-Detailed/-Examples>
- basic way to use command
- Detailed parameter shows more than the default Get-Help command
- Examples parameter gives you just examples of how to use command
- Full is the combination of both parameters mentioned previously mentioned
- Get-Command -Name <word>
- If you run Get-Command on its own, it will list every command known on your computer system. Using the name parameter
- Get-Command *wildcard* -CommandType <cmdlet>
- this command comes in handy when you want to filter the results. If you’re looking for a command that starts with a b, you put in b* in the wildcard slot. *b is for when you’re looking for a command that ends with the letter b. typing *word* would mean you’re searching for a command that contains word within it.
- CommandType isn’t important for this lesson, but is useful when using wildcard for searching for commands
- Show-Command <command>
- This will open a separate window with each available parameter associated with it.
Takeaway
I hope this are a good starting point for you for diving into PowerShell. It can be very overwhelming to grasp the concept of this language. It has so much utility and nuance that is can be daunting. There is also no way to remember every single command. There is a good chance you will use every command anyway. Knowing this, it’s important to be able to quickly look up the command, document it if necessary, and then use it to solve problems.
As always, if you need more info you can go to the Microsoft website for more documentation. Hope this was helpful!