Windows PowerShell Explained: What it is and How it Works

Photo of author

By Victor Ashiedu

Published

Have you heard of Windows PowerShell but wondering what it is all about? This simplified but detailed guide explains Windows PowerShell.

Overview

Windows PowerShell is a task automation tool. Starting from Windows PowerShell 3.0, Microsoft compiled PowerShell on .NET CLR (Common Language Runtime).

PowerShell is not just a command line tool. In addition to having a command-line shell, it also comes with a scripting language.

Earlier I mentioned that Microsoft built this tool using .NET CLR (Common Language Runtime). This is the newer version of PowerShell.

As a matter of fact, the first version of PowerShell was based on .NET Framework. This initial version of PowerShell only works on Windows Operating Systems.

In 2016 Microsoft modified PowerShell to run on .NET Core and made it an open-source and cross-platform tool. This change meant that it can now run on some Linux distros (specifically, CentOS and Ubuntu) and Mac Operating Systems.

Microsoft calls the new open-source tool “PowerShell Core.” This is different from “Windows PowerShell,” which runs only on Microsoft Windows.

How Windows PowerShell Works

If you recollect, I mentioned that from PowerShell version 3.0, Microsoft built the latest PowerShell on .NET CLR (Common Language Runtime). So, to understand how Windows PowerShell works, we need to understand how the Common Language Runtime (CLR) works.

However, you cannot discuss .NET CLR without the .NET Framework. So, what is the relationship between the .NET Framework, .NET CLR (Common Language Runtime), and PowerShell?

The .NET Framework is the software framework that incorporates the Common Language Runtime (CLR). In addition to incorporating Base Class Libraries, .NET Framework also contains Base Class Libraries.

Essentially, the Common Language Runtime (CLR) manages the execution of .NET programs. In other words, programs like Windows PowerShell written in .NET Framework execute in CLR software environments.

Earlier, I mentioned Base Class Libraries (BCL). You can also call BCL Framework libraries.

These libraries are at the core of the functionality of the .Net framework that offers PowerShell its functionality. To learn more about BCL, visit Framework Libraries.

Features of Windows PowerShell

Having spent the last two sections discussing the tech part of PowerShell, let’s now discuss what will benefit most people that want to use PowerShell.

In this section, I will be highlighting the core features of Windows PowerShell from a SysAdmin’s point of view.

The PowerShell Cmdlets are Defined in Verb-Noun Named Pairs

Windows PowerShell cmdlets are named in Verb-Noun pair. PowerShell executes cmdlets and returns .NET Framework objects displayed as outputs to the pipeline.

Cmdlets are different from Cmd commands. While Cmd commands are stand-alone executables, PowerShell Cmdlets are instances of .NET Framework classes.

PowerShell Cmdlets Support Aliases

Like Command Prompt commands, Windows PowerShell Cmdlets support aliases. The alias of a cmdlet is the short version of the cmdlet.

Aliases make it easy to remember Cmdlets. As an example, the alias of Where-Object is “?” (without the quotes).

In another example, the alias of Get-ChildItem is dir.

So, instead of using Where-Object in a PowerShell command, I can use ?. Also, instead of using Get-ChildItem, you can use the short version of the cmdlet (dir)

In the example, I have used the aliases of the Get-ChildItem (dir) and Where-Object (?) cmdlets.

dir "D:\DevOps-Projects" | ? {$_.name -eq "Microsoft-containers"}

Here is the result of the command in PowerShell.

To get common Cmdlet aliases, enter the cmdlet below into the Windows PowerShell command shell, then press enter.

Get-Alias

You can then learn the aliases for common Cmdlets. You can use these aliases in commands and scripts in place of their cmdlets.

Features Of Windows PowerShell

Windows PowerShell Cmdlets Support Pipeline

Another important feature of PowerShell is its support for pipelines. A pipeline character (|) allows you to use a cmdlet’s output as the next cmdlet’s input.

To pipe a Cmdlet to the next, simply include the pipeline character, (|) between the two cmdlets. Here is an example.

Get-Process notepad | Stop-Process

The first command-let, Get-Process will return the notepad process while the second cmdlet, Stop-Process stops the process. However, not all command-lets accept pipeline input.

PowerShell Supports Variables

One of the features of PowerShell is the use of variables. In PowerShell, you use variables to store all types of values.

Furthermore, there are different types of variables. Some common variables are user-created, automatic, and environment variables.

Talking about user-created variables, to create one, start with a dollar sign, followed by the name of the variable. You can then use the equality operator (=) to save values into the variable.

For example, to create a variable (TestVariable) and save the string “get help here” to the variable, I will use the command below.

$TestVariable = "get help here"

Apart from creating variables and assigning values to them, you can create empty variables. To create and use the Set-Variable cmdlet. To demonstrate this, I will create a variable called EmptyValriable.

Set-Variable EmptyValriable

As I mentioned earlier, the EmptyValriable variable has no value stored. But to store a value in the variable, I will run the command below.

Set-Variable EmptyValriable -Value "Value now added to this variable"

Windows PowerShell Supports Commenting

When you start scripting in PowerShell, you’ll need to add comments. There are two primary ways you can add comments in PowerShell.

Firstly, you can turn a line in a PowerShell code into a comment by adding the # in front of the code. For example, the line below will be commented out, and Windows PowerShell will not execute the line.

#this is a comment. PowerShell will not execute anything in this line

Another way to add comments in PowerShell is to use what is called “comment-based help”. In the last example, I used a single # character to define a line as a comment.

However, in some instances, you may want to add multiple comments. To do this, add the comment between <# #>.

Here is an example.

<#
everything here is a comment and PowerShell will not execute them
#>

Benefits of Windows PowerShell

In-built Help Feature

When you start out using PowerShell, one of the biggest challenges you may face is finding commands. The good news is that PowerShell has cmdlets designed to help you with that.

To list all commands in your computer, use the Get-Command cmdlet. In addition to finding cmdlets, you can also use the Get-Help command to learn how to use a cmdlet.

Command Competition Capabilities

As you progress in your knowledge of Windows PowerShell, you will have an idea about cmdkets you need to perform certain tasks.

However, sometimes, you may not remember the full cmdlet. But, if you know the first few words, type them into the PowerShell console, then press the tab key.

As you press the tab key, the shell will display possible cmdlets. This feature also extends to parameters.

You can use the command completion capabilities of PowerShell to display all available parameters available in a cmdlet.

Manage Multiple Computers Remotely

PowerShell has numerous cmdlets you can use to connect to and manage remote computers. These cmdlets allow you to connect to multiple remote computers and perform tasks.

Import Remote PowerShell Modules to Your PC

By default, you can run cmdlets installed on your computer.

However, if you need to you can import remote PowerShell modules and run them from your computer. A common example is importing Office 365 modules or Azure AD cmdlets to your computer.

Makes Administration Tasks Easier

Sysadmins that perform repeat tasks will love PowerShell.

This is because this powershell automation tool is built to automatic repeat tasks. As a Sysmadmin, if you can automate tasks that you would normally perform manually you can use your time for other tasks.

This will improve your overall efficiency and improve your productivity.

Drawbacks of Windows PowerShell

There is no piece of technology that is all good and PowerShell is no exception. This great tool has some disadvantages.

Here are some of them:

PowerShell Remoting Creates Some Security Concerns

Some of the things that make PowerShell beneficial also creates some problems.

One of those features that could cause you problem is the remoting capability of PowerShell. Before you can successfully make PowerShell connections to remote computers, some ports needs to be opened on both the remote computer.

It is also important to mention the risks posed by WinRM (a requirement for PowerShell remoting).

All these create some potential vulnerabilities.

Downloaded Scripts Pose Security Risks

PowerShell scripts downloaded from the internet could pose potential risks. Before you run a PowerShell script you download from the internet, make sure that you trust the website.

PoweShell has some in-built mechanisms to protect your computer from potentially malicious PowerShell scripts. For example, if you try to import a script you downloaded from the internet, PowerShell will warn you and then expressily ask you to allow the action.

PowerShell skills are Not Widespread Yet

This is not a major drawback but it is worth mentioning.

Most Windows SysAdmins do not like command-like tools. So, even though PowerShell is relatively easy to learn and offers a lot of benefits learning it requires some effort.

Unfortunately, not so many people are willing to put the effort. So, I see this as a drawback because as long as a SysAdmin has not learned how to use this scripting tool, the benefits will elude the person.

Frequently Asked Questions

1. What is Windows PowerShell used for?

Windows PowerShell is a scripting language used for automating Windows tasks. From v6.0 Microsoft made PowerShell a cross-platform too and changed its name to “PowerShell Core”.

What this means is that, in addition to automating Windows tasks, you can now use PowerShell to automate Linux and macOS tasks as well.

2. Do I need Windows PowerShell on my computer?

Not necessarily. Although Microsoft installs PowerShell on Windows Operating Systems by default, you do not need to have it and may decide to uninstall it.

However, my recommendation is that you do not uninstall PowerShell unless you have a specific reason to do so. Talking about uninstalling PowerShell, one reason most of our readers have given for uninstalling it is if PowerShell keeps opening on startup.

In that regard, if you need to uninstall PowerShell, follow the steps in this link – Uninstall Windows PowerShell Completely.

3. Is Windows PowerShell the same as Command Prompt?

No. While Windows PowerShell is an object-oriented scripting task automation toll built on .Net Framework, Command Prompt is a native Windows console application.

To read our full guide that compares Windows PowerShell and Command Prompt, visit Windows Powershell vs CMD: Differences and Similarities.

4. Why do I have Windows PowerShell instead of Command Prompt?

According to Microsoft, PowerShell is replacing Command Prompt. The reason Microsoft gave for replacing Command Promt with PowerShell is “to create the best command-line experience”.

With that said, as at July 2022 when I updated this guide, Command Promt is still available on Windows 11. For example, if you search cmd, you can still access Command Prompt.

However, Windows 11 now comes with a “Windows Terminal” which launches Windows PowerShell. You can access “Windows Terminal” when you right-click Start Menu.

Moreover, in Windows 11, when you right-click a folder, or your desktop, you have the option to “Open In Windows Terminal”.

5. Can PowerShell do everything CMD can?

Yes. By default Windows PowerShell runs all CMD commands. However, sometimes PowerShell uses a different syntax to run CMD commands.

6. How do I remove PowerShell from Windows 10?

To remove PowerShell from Windows 10, follow the steps below:

i. Open Command Prompt as administrator
ii. Then, enter the command below into command prompt and press enter key on your keyboard.

Dism /online /Disable-Feature /FeatureName:”MicrosoftWindowsPowerShellV2Root”

7. How do I run PowerShell?

The simplest way to open PowerShell shell is to search “PowerShell”. Then, from the search results, click Windows PowerShell.

8. Is PowerShell the same as Linux?

No. Linux is a Unix-based Operating System.

On the contrary, PowerShell is a Windows shell built on .Net Framework and used to automatic Windows tasks. It is important to mention that recently, Microsoft made PoweShell open source and cross-platform.

So, you can now install “PowerShell Core” (the open source version) in Linux and macOS.

9. Why is PowerShell running when my computer starts?

There are so many reasons PowerShell may open when your computer starts up. To read the details and how to stop this from happening, read our guide – Why Does PowerShell Open On Startup and How to Stop It

10. Is PowerShell free?

Yes. PowerShell is free and ships with Windows Operating Systems.

Conclusion

I have no doubt in my mind that Windows PowerShell is one of the best tools Microsoft created in recent years. One of the things that makes this new shell Powerful is that it is built on the .Net Framework.

This makes it possible for SysAdmins and developers to automate anything (literally, anything!) in Windows.

Another major thing PowerShell has going for it, is its Verb-Noun cmdlet formatting. This makes cmdlets easy to remember and use.

However, you do not need to remember cmdlets since Windows PowerShell has built-in help functionalities.

For example, you can use the Get-Command cmdlet to find cmdlets you need. Then, use the Get-Help cmdlet to learn how to use the cmdlet.

I hope that I have successfully introduced you to Windows PowerShell and convinced you that it is worth learning this new shell!

We’re keen to hear what you think about this article as it helps us improve. Giving us your feedback – positive or negative – is as easy as responding to the “Was this page helpful” question below.

We review our readers’ feedback and update our articles based on the feedback we receive.

Finally, you may find other PowerShell guides helpful. To read more PowerShell guides, visit our PowerShell guides page.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

We're committed to writing accurate content that informs and educates. To learn more, read our Content Writing Policy, Content Review Policy, Anti-plagiarism Policy, and About Us.

However, if this content does not meet your expectations, kindly reach out to us through one of the following means:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

Leave a comment