Skip to main content

Command Palette

Search for a command to run...

Learn Windows PowerShell commands like a Linux User

Updated
8 min read
Learn Windows PowerShell commands like a Linux User
P

On a daily basis I fix bikes. Besides that, I devote nearly all my life to sharing knowledge with others. I studied urban design. Support me on Ko-fi if you find valuable what I do :) https://ko-fi.com/piotropoka

Whether you're a Linux user used to commands as a default way of navigating through the system or you're just a Windows user who'd like to prove that he's advanced, Windows might feel hard to use with PowerShell. In this guide I'll show you how to find most of the features or commands you need and the way of learning them.

Table of Contents:

  1. What you'll learn

  2. Technical introduction

  3. Setting up the Get-Help command

  4. Understand any PowerShell command, by using Get-Help command

  5. Find any command with Get-Command

  6. Get all possible aliases with Get-Alias

  7. Get whatever you need from your searches with Select-Object command

  8. BONUS Show alternative aliases that you can use with Get-Alias

  9. Summary and free cheat sheets!

  10. Additional reading

If you prefer, you can also watch this tutorial here:

1. What you'll learn

After this tutorial, you should be able to use:

  • Get-Help <command> -Detailed to learn whatever you need about any PowerShell command (Point 4)

  • Get-Alias -Definition <command> to find all possible aliases for any PowerShell command (Point 6)

  • Get-Command <alias> | Select-Object -Property * and Get-Command <command> | Select-Object -Property * to see all parameters you can use with these commands (Point 7)

  • Get-Command <alias> | Select-Object -ExpandProperty <parameter> and Get-Command <command> | Select-Object -ExpandProperty <parameter> to get value of any parameter (Point 7)

  • Get-Alias -Definition $(Get-Alias <alias> | Select-Object -ExpandProperty Definition) to get alternative aliases to the alias that you've used until now (Point 8)

2. Technical introduction

One of the commands you're most likely to use inside Windows PowerShell is: Get-ChildItem, better known as: ls and dir. It works the same as Linux's ls command, which shows you the contents of a chosen folder. Somewhere in the future you might learn that it actually has many more powerful features. But how do I even know about them?

For that I use Get-Help command

3. Setting up the Get-Help command

Well, at the beginning Get-Help might not necessarily work very well. You might see the note similar to this one:

powershell hinting to use Update-Help

So, according to it, we should first get the newest information about PowerShell functionalities by typing Update-Help. It might take up to 5 minutes to download everything you need, so be patient. After it's finished (you'll see that you can type again), go to the next step.

4. Understand any PowerShell command, by using Get-Help command

You can now try the code below to see different results

Get-Help Get-ChildItem
Get-Help Get-ChildItem -Detailed
Get-Help Get-ChildItem -Examples

The first one explains you what does the command do and what options it has (although in not very human-friendly way ).

Get-Help  showing only description of command

Ironically, -Detailed parameter is more understandable as it shows every option that you can use with this command, explains them and also gives you examples of use. This is the most used option.

Get-Help  showing everything we need to know about command

And the last one you can guess… It only shows you the examples of use for this command. They are sometimes very complex and quite helpful, as you'll often learn some new ways of usage for this and any other command

Get-Help showing only example use cases of command

Get-Help can be of your interest in some other scenarios too. Just type Get-Help alone in order to learn more about this command and its options or try

Get-Help Get-Help -Detailed

5. Find any command with Get-Command

Sometimes you'll see an answer on StackOverflow with an alias (shorthand version of command) that you've never seen before and you'd want to learn which command it is. That's where Get-Command comes to your aid. Alone, Get-Command shows you most of the commands used in PowerShell. But if you type it with alias like this:

Get-Command gci

It will show you, which command that alias is referring to! The same, can be achieved with Get-Alias gci

Get-Command and Get-Alias giving the same results

NOTE: Both Get-Alias and Get-Command will also show us the commands created by ourselves, not only the system ones. For tutorial on how to create your own command, checkout the link in Additional reading section.

IMPORTANT! Some commands are hidden or not that often used and you'll see lists of them only with Get-Command -ALL or Get-Command *. For example: when listing all commands, you can see whoami.exe only when using the * option

Get-Command -ALL | echo > ~\Documents\some_text_file.txt
Get-Command * | echo > ~\Documents\some_other_text_file.txt

Both of these commands will send the output to the file in your Documents folder, which you can now open and compare the two files with each other

different sizes of files depending on which command we used

6. Get all possible aliases with Get-Alias

Using only Get-Alias will show you all existing aliases on your file system, so it works similarly to Get-Command. On the picture below you can see results from Get-Alias on the left and from Get-Command on the right.

Results of Get-Alias on the left and Get-Command on the right

The basic syntax for getting all the aliases of any command you want is: Get-Alias -Definition Your-Command.

PS System32> Get-Alias -Definition Get-ChildItem
CommandType     Name                                               Version    Source
Alias           dir -> Get-ChildItem
Alias           gci -> Get-ChildItem
Alias           ls -> Get-ChildItem

For that, you only need to know the name of the command. However, you can get similar results, without even knowing that name, just by using an Alias. I'll show you that in BONUS section.

Okay, but how did I know that I can use an option like -Definition? That's where Select-Object command comes to our aid!

7. Get whatever you need from your searches with Select-Object command

This command should give you all necessary information about any alias.
Get-Command <alias> | Select-Object -Property *

Get-Command  vs Get-Alias

As you can see, there's the Get-ChildItem in quite a few places appearing, so you can access is it with either ReferencedCommand and ResolvedCommand instead of -Definition, like in this example:

Get-Command gci | Select-Object -Property ResolvedCommand

You can adjust the parameter of this command to get whatever value you'd like. You can also see that in this example Get-Command gives us more results than Get-Alias, but usually you should be able to get the same results from both of these commands. I put the blame on the buggy Windows code. As you can see it’s worth to sometimes try different solutions, despite the fact that all of them should work. You might find different results.

Try this command for even more different results

Get-Command Get-ChildItem | Select-Object -Property *

Interesting thing- if you ever need to access a value of such property (for example, to use in a script), you can get just that with -ExpandProperty

Get-Alias gci | Select-Object -Property Definition
Get-Alias gci | Select-Object -ExpandProperty Definition

ExpandProperty vs Property

8. BONUS! Show alternative aliases that you can use with Get-Alias

Here's a code from me, that shows you all possible aliases to certain command based only on its alias (echo used as an example).

Get-Alias -Definition $(Get-Alias echo | Select-Object -ExpandProperty Definition)

So, for example, you can find ls and dir, by typing gci and you don't have to know that this command is called Get-ChildItem!

PS System32> Get-Alias -Definition $(Get-Alias gci | Select-Object -ExpandProperty Definition)
CommandType     Name                                               Version    Source
Alias           dir -> Get-ChildItem
Alias           gci -> Get-ChildItem
Alias           ls -> Get-ChildItem

Part of the code in brackets () has task of retrieving the full name of the command (Definition), to which alias echo refers to. As I showed with examples in Point 6 -ExpandProperty gives you only just the value of Definition. It's perfect to pipe (transfer) its output into another command.

9. Summary and free cheat sheets

After this tutorial, you should be able to use:

  • Get-Help <command> -Detailed to learn whatever you need about any PowerShell command (Point 3)

  • Get-Alias -Definition <command> to find all possible aliases for any PowerShell command (Point 5)

  • Get-Alias <alias> | Select-Object -Property * and Get-Command <command> | Select-Object -Property * to see all parameters you can use with these commands (Point 6)

  • Get-Alias <alias> | Select-Object -ExpandProperty <parameter> and Get-Command <command> | Select-Object -ExpandProperty <parameter> to get value of any parameter (Point 6

  • Get-Alias -Definition $(Get-Alias <alias> | Select-Object -ExpandProperty Definition) to get alternative aliases to the alias that you've used until now (Point 7)

If you find what I wrote here valuable and would like to show how you appreciate my effort, here's how you can help:
Buy me a coffee: https://ko-fi.com/piotropoka
Or rate me on Github :) (That is free!) https://github.com/NotBlackMagician
Or follow me on Mastodon to help me reach further audience :D

Here are used commands with examples. Feel free to copy and save that somewhere or you can download a .txt file with that cheat sheet from here: https://github.com/NotBlackMagician/NBM-cheat-sheets

GETTING INFO ON HOW A COMMAND WORKS
Get-Help <command> -Detailed - Shows information about command, how it works, what options you have and gives you examples of use with other commands
EXAMPLES:
Get-Help Get-ChildItem -Detailed Get-Help
gci -Detailed Get-Help Get-Help -Detailed

SAVING COMMAND'S OUTPUT, SO YOU CAN EASILY READ IT
Get-Help <command> -Detailed | echo > ~\Documents\file_name.ext - saves the output in file in your “Documents” folder. Later, you can open it
EXAMPLES:
Get-Help Get-ChildItem -Detailed | echo > ~\Documents\command_output.txt
Get-Help Get-ChildItem -Detailed | echo > ““~\Documents\"command output.txt””

FINDING COMMAND BY ALIAS
Get-Command <alias>
Get-Alias <alias>
EXAMPLES:
Get-Command gci
Get-Alias gci

FINDING ALIASES
Get-Alias -Definition <command>
EXAMPLES:
Get-Alias -Definition Get-ChildItem

GET ALL PARAMETERS OF COMMAND OR ALIAS
Get-Command <command> | Select-Object -Property *
Get-Alias <alias> | Select-Object -Property *
EXAMPLES:
Get-Command Get-ChildItem | Select-Object -Property *
Get-Alias gci | Select-Object -Property *

GET SPECIFIC PARAMETER OF COMMAND
Get-Command <command> | Select-Object -Property Definition
Get-Command <command> | Select-Object -ExpandProperty Definition
EXAMPLES:
Get-Command Get-ChildItem | Select-Object -Property Definition
Get-Command Get-ChildItem | Select-Object -ExpandProperty Definition

10. Additional reading

Recommended lecture- this book helped me and will most likely help you in both beginner and intermediate PowerShell projects. It's not sponsored, I just feel it's fair to at least give some credit to the author who made a brilliant guide. Grab it here: http://leanpub.com/powershell101