What Are the Basic PowerShell Commands?
Newbies to PowerShell can benefit from learning a handful of basic commands. Here are six PowerShell cmdlets you should know.
October 17, 2022
Many people find PowerShell to be somewhat intimidating, not just because it is a command line environment but because there are thousands of commands available.
The total number of PowerShell commands – or what Microsoft calls cmdlets (pronounced "command-lets") – varies widely based on the Windows version you run and on how Windows is configured. Even so, it is not uncommon for a Windows deployment to support over 12,000 PowerShell cmdlets!
The good news is that you don’t have to learn all these thousands of cmdlets. If you are just getting started with PowerShell, it probably makes the most sense to learn the basic commands.
What Are the Basic PowerShell Commands?
There is no official list of “basic” PowerShell cmdlets. Even so, there are a handful of cmdlets that most experts would agree are foundational. These cmdlets are very commonly used in conjunction with other cmdlets.
PowerShell cmdlets that you should know include the following:
Get-Command
Get-Help
Clear-Host
Set-Location
Get-ChildItem
Get-Alias
Get-Command
The first important PowerShell cmdlet is Get-Command. When used by itself, the Get-Command cmdlet will display a list of every known PowerShell cmdlet. Typically, this list is in the thousands.
While Get-Command might not seem particularly useful, it’s important that you know it. That’s because it can help you to find the cmdlet you need in a given situation.
Most PowerShell cmdlets are made up of two words, a verb and a noun, which are separated by a dash. In the case of Get-Command, Get is a verb and Command is a noun. A verb or a noun that is used in one cmdlet is often supported by other cmdlets, as well. The verb Get, for example, is used in a huge number of cmdlets. Get usually instructs the cmdlet to return a list of information (examples: Get-Users, Get-Process, etc.).
If you want to know all the cmdlets that support Get, just type:
Get-Command Get-*
Get-Help
Another must-know PowerShell cmdlet is Get-Help. Whereas Get-Command can help you to find the name of a specific cmdlet, Get-Help can show you how to use a cmdlet.
To use Get-Help, just type the command followed by the name of the cmdlet that you need help with. For example, if you want to know how to use Get-Command, you would type this:
Get-Help Get-Command
You can see what this looks like in Figure 1.
Basic PowerShell 1
Figure 1. The Get-Help cmdlet is used to display the syntax of any other PowerShell cmdlet.
Clear-Host
The Clear-Host cmdlet is one of the easiest PowerShell cmdlets to use. The cmdlet is used to clear the screen. Hence, if you need to clear the screen, just type Clear-Host.
As a shortcut, you can also use the CLS command to clear the screen. CLS is a leftover from the days of DOS and is an alias to the Clear-Host cmdlet (more on aliases in the Get-Alias section below).
Set-Location
The Set-Location cmdlet is used to navigate the file system. It can be used as an alternative to the CD command (CD is a DOS leftover and stands for Change Directory).
To use Set-Location, just append the -Path parameter, then provide the path to go to. For example, if I wanted to navigate to C:UsersBrien, I would type this:
Set-Location -Path “C:UsersBrien”
The next figure provides an example of Set-Location. Incidentally, Set-Location can also be used to navigate the Windows registry.
Basic PowerShell 2
Figure 2. You can use the Set-Location cmdlet to navigate the file system.
Get-ChildItem
Get-ChildItem is another useful PowerShell cmdlet. When you type the Get-ChildItem cmdlet by itself, PowerShell will display the contents of the current folder (see Figure 3).
Basic PowerShell 3
Figure 3. The Get-ChildItem cmdlet is used to display a folder’s contents.
Get-Alias
As you become more familiar with PowerShell, you will find that some commands do not adhere to the previously mentioned verb-noun naming convention. Such commands are typically aliases.
An alias is just an alternative name for a PowerShell cmdlet. In some cases, an alias is simply used as a shortcut. For example, you can type Select instead of Select-Object because the word Select is an alias for Select-Object.
In other cases, aliases are used for backward compatibility purposes. For example, in the days of DOS, the DIR command was used to view the files within a folder. The DIR command is still used within the Windows Command Prompt window. Even though PowerShell uses a different command (Get-ChildItem), DIR is used as an alias.
The Get-Alias cmdlet can help you to figure out which PowerShell cmdlet an alias points to. For example, to find out which cmdlet was in fact being used when you typed DIR, you could type:
Get-Alias DIR
This command would show you that DIR is an alias for Get-ChildItem, as shown in Figure 4.
Basic PowerShell 4
Figure 4. The DIR command is an alias for Get-ChildItem.
About the Author
You May Also Like