Learn PowerShell, using PowerShell
PowerShell is more than just a command line shell. It is a configuration management framework that the command line shell is part of, but also a scripting language.
It is more powerful than the Windows command prompt but also more intimidating. While it has been there for more than a decade, most Windows users are probably not very familiar with PowerShell.
This guide provides you with information on learning PowerShell, by using PowerShell. This may sound confusing at first, but it is not really. What I try to do here is to give you commands at hand that help you understand PowerShell commands.
Please note that this is not a complete PowerShell tutorial that teaches you all there is to know about it. It is designed to give you tools at hand that you can use whenever you stumble upon PowerShell commands, or want to do something using PowerShell but don't know how to.
Starting PowerShell
It all begins by starting a new PowerShell command line shell.
- Regular shell: Tap on the Windows-key, type Powershell.exe, and run the result.
- Elevated shell: Tap on the Windows-key, type Powershell.exe, hold down the Shift-key and the Ctrl-key, and run the result.
Note: Some commands, the updating of help files for instance, may require elevation.
The first tip: Get-Command
The command Get-Command lists all PowerShell Cmdlets when you run it. This may not look super useful right away.
If you use Get-Command | Format-List * instead, you get a formatted listing instead that lists, among other things, the help file URI of each command.
If you want all those help file links, use Get-Command | Get-Help | Out-File c:\ps\help.txt. This gets all help topics of all cmdlets, and saves them to the help.txt file on c:\ps.
You may also filter the listing, by using a command such as Get-Command *process. This lists all commands with process in their name (meaning all that manipulate processes).
The second tip: Help
First thing you may want to do is update the help file. Not all help topics are available by default, and running the command ensures that they are up to date and available locally.
Run Update-Help, and wait for the process to finish.
Want to force updates and all? run the command update-help -Module * -Force instead.
As far as help commands are concerned, the main one is get-help "cmdlet", e.g. get-help get-command to display information about get-command. Running get-help displays the following for the selected command.
- Synposis: short bit on what the cmdlet does.
- Syntax: all parameters and options that are supported.
- Description: more information on what the cmdlet does.
- Related Links: Web Links, as well as Cmdlets that may provide additional information.
- Remarks: some general tips.
You may also display the help of a cmdlet by appending -? to its command, e.g. Update-Help -?.
The command get-help -detailed displays detailed information about the command. Please note that the command does not work on all cmdlets.
The command get-help "command" -full lists all information that is available. This includes examples, notes, inputs and outputs, and more on the screen.
You may display the online version of help for a command by using the -online parameter, e.g. Get-Help Format-List -Online.
The command Get-Help * on the other hand lists all help topics that are available.
To get help about parameters, use the command Get-Help "command" -Parameter "Name", e.g. Get-Help Format-List -Parameter GroupBy.
Last but not least, you may use Get-Help "word" to list topics that include the word you have specified, e.g. Get-Help process.
Tip 3: Examples
Sometimes, all you need is an example to find out more about a cmdlet. You can use the command get-help "cmdlet" -examples, e.g, get-help write-verbose -examples, to list examples that reveal how the cmdlet is used.
Tip 4: Display help output in extra window
To display help content in a new window instead of the one you run the command in, use get-help "command" -ShowWindow, e.g. get-help write-verbose -ShowWindow.
Tip 5: Learn and use aliases
Aliases help you type commands faster. The best way to know about aliases is to run get-alias. The command lists them all in the interface.
Extra Tip: Resources
The following online resources are excellent when it comes to learning more about PowerShell:
- Cmdlet listing at Technet -- Includes information on using important cmdlets, but also on popular topics such as files and folders, dates and times, or scripting techniques.
- Microsoft PowerShell Core Reference on MSDN - Lists syntax, examples, parameters,and details.
- Windows PowerShell Essentials for the Busy Admin Series -- Series by Microsoft on learning PowerShell.
I have found useful;
Get-Module -ListAvailable
That lists modules, so pick one you like the look of and;
Get-Command -Module Defender
To see all commands for the module.
Thanks. Very handy. Bookmarked it and might use it someday, if I muster the courage.
As someone who validates powershell scripts made by various members of the team on a daily basis, I’d say the last tip(learn and use alias) is actually a terrible one. Powershell is nice to read, like python, because it is very verbose and self descriptive, but when you start to use aliases, it becomes a total pain to decipher. Tip 5 should be : Aliases exist, don’t use them in the name of readability/maintainability.
actually, the tip is great. If I come from Linux, I don’t want to learn powershell for some basic command line usage. Just type Linux commands and it works. If you’re writing scripts, it is a different matter.
Agree. Alias makes the scripts hard to read even for someone used to PowerShell.
thanks, been looking for an article like this