PowerShell Commands Every PC User Should Know

PowerShell gives you the ability to take command of your PC for real!
Odin Odin (181)
0

It’s not sorcery, it’s PowerShell! Powershell is a command language built into Microsoft Windows that offers a slew of powerful functions right out of the box while, for advanced users, the whole operating system can become an exciting playground. Even if you’re just looking to understand a few of the most basic commands and functionalities of PowerShell, however, you’re off to a good start with taking control of your computer.

Why would you want to understand PowerShell?

Why would you want to understand PowerShell? If you’re stuck on a particularly weird glitch, if your computer is having difficulties logging into a wireless network, or if you’re interested in creating powerful automated processes that can run on your computer and take care of complex or demanding tasks far easier than you could on your own then PowerShell is the way to go. It affords users the ease-of-use of the old command line interface with the power of a scripting language, allowing you to do more with your PC without a huge learning curve.

Command of the code: cmdlets

PowerShell “cmdlets” are scripts that are activated to undertake some specific action, like downloading something from the web or running a diagnostic. You can type in something like “get-help” and that tells the computer to execute an action or a series of actions. Most of the time, when running cmdlets you’ll be handling them in a limited user environment that tries to keep you from doing anything that could disrupt your computer’s functioning, but PowerShell does give you a lot more control over your computer than many users will be familiar with. Because of this, the first thing we want to do is create a restore point to make sure that any changes you make accidentally can be undone easily. Anyway, restore points are just good to have around so it’s good practice to create one even if you’re not using PowerShell for anything serious.

Run as administrator

Sometimes you’ll need to run the PowerShell application as an administrator in order to execute the cmdlet that you need to use. This can be easily accomplished by going to the windows search bar and typing in PowerShell, after which you can click on the option for “Run as administrator”. Or, if you have PowerShell pinned to your taskbar, you can find this option by right-clicking it.

With that out of the way, let’s get into the fun stuff!

Posted in these interests:
PowerShell Logo
h/powershell5 guides
h/technology89 guides
h/windows45 guides
PowerShell: Get-Help
PowerShell: Get-Help

The first you cmdlet you’re going to want to be aware of is the one that gives you an overview of what you can do! This is where get-help comes in handy. By typing get-help into PowerShell you’ll receive a comprehensive overview of what PowerShell is and you’ll be able to get a handle on the basic structure of its functionality. You can access documents on the web for more advanced help through this interface or even download help files than can then be explored within PowerShell itself. But the help command offers more.

Get-Help *

This cmdlet will give you a list of all the cmdlets that you have access to at the moment. This is going to be a pretty big list in most circumstances, but it can be a lot of fun to explore all the possibilities.

Get-Help

This cmdlet will download all the latest help files from the internet so they're available right inside your PowerShell window.

Get-Help <command name>

Instead of “” you’ll just type the name of the command you want to explore (you don’t need the brackets).

With this cmdlet, you can get basic information about a specific command. It will provide a simple explanation of a cmdlet’s functionality so you can understand what it does.

Get-Help <command name> -Full

This command provides you with a more detailed explanation of what a specific cmdlet does.

Get-Help <command name> -Example

This help command goes even farther, providing you with an example of how the command might be used. In this way, you can fully explore the PowerShell environment without leaving PowerShell at all!

PowerShell: Get-Command
PowerShell: Get-Command

Get-Command allows you to retrieve information about specific commands or sets of commands in a quick and efficient manner. There are a ton of options with Get-Command that extend well beyond what a basic user would need, so we’re going to just focus on a couple of the basic ones, specifically those that will help you navigate the available commands.

Get-Command -CommandType

This allows you to get a specific list of cmdlets based on their type. For the most part, a new user will probably just use the “cmdlet” type as we see in my next example.

Get-Command -Type Cmdlet | Sort-Object -Property Noun | Format-Table -GroupBy Noun

This more complicated phrase tells the computer that the user wants to get a list of all cmdlet type commands, that it wants to sort them alphabetically by the noun in their name, and then displays them in noun-based groups. This makes it easy to explore some of the possible commands. It is also a good example of how more complicated tasks can be accomplished using PowerShell — one a user is familiar with the syntax, using PowerShell is often the fastest method of getting things done.

Get-Command -Name <name> will pull up a command by its exact name.

-UseFuzzyMatching

This is one of my favorite commands because it allows you to search for things in the rough ballpark of a known name. This can be useful if you don’t know the name of a cmdlet you’re looking for, but might guess part of the name, or if you’re prone to misspellings. In either case, what this does is try to find commands that most closely match what you type.

This might look like the following:

Get-Command -Name <name> -UseFuzzyMatching

PowerShell: Get-Item
PowerShell: Get-Item

Alright, but what about some specific commands in PowerShell that allow you to interact with your system, that’s what we’re here for, right?

Get-Item

Using the Get-Item command, you have access to a powerful tool for searching your computer for a file that you need. This can be faster in many cases than trying to use the GUI (graphical user interface) search provided by Microsoft.

You use this command by specifying the location on your computer that you want to search. For instance, you could find your “C:” harddrive location by using the command like so:

Get-Item C:

Or you could go deeper into a directory and see everything contained in that directory, by using “*”.

Get-Item C:\users\<user>\*

Would return a list of all the directories contained under that user’s profile (and these would likely be further directories like “documents” and “downloads.”

As always, the best way to see how this works is to play around with it for a little while.

PowerShell: Get-Content
PowerShell: Get-Content

Get-Content

Using this command, you can get the content of a file on your computer. In most cases this will be a massive wall of confusing code, but in the above case it’s just the contents of a plain text file I placed on my desktop for this purpose. All you need to do is specify the location of the item in question.

On it’s own, this command is quite simple, but learning about it here sets you up for learning how to use it in conjunction with other commands where it can become quite powerful.

PowerShell: Service
PowerShell: Service

Using the “Service” command is one of the most powerful and useful, especially if you’re administering a network, but also if you’re just an ordinary user. What this does is allow you to see what services are running on your computer and control them.

Get-Service

This will grab a list of all the services running on your computer, from main programs like your browser, to all the other programs running in the background that make your computer run.

You can also use the following commands to control a service directly, say, if it’s frozen.

Restart-Service <service name>

Or you can stop it:

Stop-Service <service name>

Or start it up again:

Start-Service <service name>

PowerShell: Get-Process
PowerShell: Get-Process

Get-Process brings up information about the processes currently running on your system, such as their memory usage and their ID.

Get-Process

Likewise you can use the “Start” or “Stop” prefix instead of Get, followed by the name or ID of a process to either stop or start a process.

PowerShell: Clear (and cycle previous entries)
PowerShell: Clear (and cycle previous entries)

Clear is a super useful command for when you've filled up your PowerShell console to the brim with help text and attempts at various commands. Rather than having to close the program and restart, just type " clear " and you'll be brought back to a nice clean slate.

Cycling through previous entries is going to help you save a ton of time retyping or copy/pasting. In the PowerShell console you can bring up previous commands that you typed by simply pressing the "Up" arrow on your keyboard! This is invaluable when you're playing around with a cmdlet and need to try several different phrasings to get it to turn out right.

Learning PowerShell changes everything!
Learning PowerShell changes everything!

These commands are all simple on their own, but they will hopefully help provide you with a framework for some of the things that you can do with PowerShell, as well as for how PowerShell functions. Learning PowerShell can allow you to create powerful scripts that let you execute complex tasks on your computer, like the one I use in my Chocolatey guide.

Learning how to navigate your computer through PowerShell instead of purely through your GUI will afford you a greater degree of control over your device as well as provide a whole new playground for how you interact with your PC.

Creating a Windows restore point with PowerShell is easy!
Odin Odin (181)
5 minutes

Windows is an incredibly versatile tool, an operating system with enough freedom to handle a huge range of tasks, from playing games to writing novels.