What is PowerShell and how do you use it?

What is PowerShell and how do you use it?

While many casual users know about the Command Prompt, only a few have heard about Windows PowerShell. PowerShell is not the same as Command Prompt - it’s a much more powerful tool that was created to replace Command Prompt, delivering more power and control over the operating system. Would you like to get a better understanding of what PowerShell is, why it’s such a powerful tool, and see what you can do with it? Then read on:

Advertisement

What is PowerShell?

PowerShell is a powerful scripting language and command-line shell that you can use to automate tasks, manage systems, and perform various operations. That’s the definition of PowerShell in a nutshell; excuse the intended pun :). However, to better understand what PowerShell is and what it’s used for, you should first know what a shell is. In computer science, a shell is a user interface that gives you access to various services of an operating system.

PowerShell in Windows 11

PowerShell in Windows 11

A shell is usually command-line based, but it can also include a graphical user interface (GUI).

Initially, Windows PowerShell was developed by Microsoft for the purposes of task automation and configuration management. Nowadays, PowerShell is open-source, and you can use it on Windows, macOS, and Linux platforms.

Using PowerShell on a Linux machine

Using PowerShell on a Linux machine

PowerShell is based on the .NET Framework, which means it can access many libraries and features of the Windows operating system, as well as interact with various services and applications, including Azure, Microsoft 365, and SQL Server.

Advertisement

The first version of PowerShell was released in November 2006 for Windows XP, Windows Server 2003, and Windows Vista. The most recent version is Windows PowerShell 7.3.6, although the latest stable builds of Windows 11 and Windows 10 still come with PowerShell 5.1. Microsoft chooses the latter still, although plans for including newer versions of PowerShell in Windows operating systems apparently do exist.

Windows PowerShell version 5.1

Windows PowerShell version 5.1

TIP: As you might have noticed in the previous screenshot, you can check what version of PowerShell you have on your PC by running this command:

$PSVersionTable

What is PowerShell used for?

Microsoft designed Windows PowerShell as a tool that helps you automate and quickly solve tedious administration tasks. For example, you can use PowerShell to display all the USB devices installed on one or multiple computers in a network, or you can set a time-consuming task to run in the background while you do other work. You can also identify and kill processes that are not responding or filter specific information about computers in a network and export it in HTML format.

How to stop a process with PowerShell

How to stop a process with PowerShell

How to use PowerShell

In order to start using PowerShell, you must first open a PowerShell console or an integrated scripting environment like PowerShell ISE. Both are available by default on Windows operating systems. On other platforms, you have to download PowerShell and install it in order to get access to the scripting language and its console.

How to open PowerShell in Windows

In Windows 11 or Windows 10, you can launch the PowerShell console by following any of these methods. One of the easiest ways is to look for PowerShell with Windows’ integrated search feature.

How to open PowerShell in Windows

How to open PowerShell in Windows

How to use PowerShell commands

PowerShell commands are called cmdlets. Their names are usually easy to understand and even memorize, as their syntax is similar to that of a regular sentence. For instance, I bet it’s easy for anyone to remember and immediately know what a PowerShell cmdlet, such as Get-Process or Copy-Item, is all about. Unlike the commands in ancient operating systems of old-style shells (DOS and Command Prompt instantly come to mind), PowerShell cmdlets are quite user-friendly. In a PowerShell vs. CMD showdown, the former will always win in terms of usability, not to mention efficiency and performance.

How to see the list of commands in PowerShell

How to see the list of commands in PowerShell

TIP: If you want to see all the available cmdlets in your PowerShell, you can use this command:

Get-Command
Advertisement

Most PowerShell commands can also be used with parameters, which are options that modify the behavior of the executed cmdlet. For example, the -Name parameter can be added to the Get-Process cmdlet if you want to specify the process to get.

How to get a process by name in PowerShell

How to get a process by name in PowerShell

A PowerShell cmdlet can output results on the screen, store them in variables, or directly send them to other cmdlets. Similarly, PowerShell also allows you to create and use variables to store values or objects. Variables are marked by the $ (dollar) sign, followed by their names. For instance, $digitalcitizen=“Life in a digital world!” or $sample= “Hello world!”.

How to set variables in PowerShell

How to set variables in PowerShell

TIP: Use this cmdlet to see all the variables in your PowerShell session:

Get-Variable

To continue, PowerShell also supports operators, which you can use when you need to make calculations or comparisons between different values or objects. For example, the + operator allows you to add numbers, while -gt tells you whether the first value is greater than the second.

How to use operators in PowerShell

How to use operators in PowerShell

TIP: You can use the next command to find all the available operators in PowerShell:

Get-Operator

Last but not least, you should also know that PowerShell supports control structures (based on conditions or loops) such as if or foreach, as well as functions. But this is already advanced scripting territory, and the scope of this article isn’t to list all the cmdlets you can run and use in PowerShell. Still, if that’s what you’re looking for, I recommend reading Ed Wilson’s Windows PowerShell Step by Step book or browse Microsoft’s official PowerShell Documentation to learn all the ins and outs of using PowerShell. You could also check this guide from Microsoft for sample scripts that give you a good idea of how to use PowerShell efficiently.

Advertisement

PowerShell vs. PowerShell ISE

On top of the standard command-line shell, you can also find the Windows PowerShell ISE. ISE stands for Integrated Scripting Environment, and it’s a graphical user interface that allows you to run commands and create, modify, and test scripts without having to type all the commands in the command line. The tool allows the development of scripts which are collections of commands where you can add complex logic for their execution. The ISE tool is designed to help Windows systems administrators who repeatedly need to run sequences of commands that manipulate the configuration of these systems.

PowerShell ISE (Integrated Scripting Environment)

PowerShell ISE (Integrated Scripting Environment)

For users with previous experience in Command Prompt and Linux, PowerShell has a list of aliases that associate names familiar to these users with the PowerShell commands. Here are a few examples: cat, dir, mount, rm, chdir, erase, sort, cls, del. For a full list of these aliases, run this command in PowerShell:

Get-Command -Type Alias

Why use PowerShell? Is Windows PowerShell needed?

PowerShell is a tool that can be incredibly useful both for home users and IT administrators. For instance, a home user can take advantage of PowerShell in order to do all kinds of things that would otherwise take a long time to perform manually: uninstall unwanted Windows apps, count files and folders, print lists of running processes, etc. Furthermore, other tasks can sometimes be performed faster and easier with PowerShell than by using the plain user interface of Windows. I can think of things like finding your IP or MAC address and even deleting partitions.

How to get the IP address in PowerShell

How to get the IP address in PowerShell

PowerShell is often the weapon of choice for IT admins, as it can significantly simplify the management of operations in corporate networks. To give you an example, let’s say you are managing a large network containing over five hundred servers, and you need to implement a new security solution that is dependent on a specific service that has to run on those servers. You could, of course, log in to each server and see if they have that service installed and running. It is possible, but it’s also likely that you take too long to finish the task. If you use PowerShell, you can complete that task in just a few minutes since the whole operation can be done with only one script that gathers information about the services running on the servers you specify and dumps them into a text file, for instance. Now that’s productivity!

How can PowerShell help you?

As you can see from this article, Windows PowerShell is an incredibly powerful tool that’s included in Windows and is also available for many other operating systems. It brings many benefits to power users and IT professionals. Furthermore, home users can benefit from using it too. Try it out, read our tutorials, and let me know what your opinion about PowerShell is. Leave a comment below and share your perspective.

Discover: Productivity Blog PowerShell Programs Recommended Windows