Windows PowerShell 101: What Is It & How Can You Use It?

Written By Farhan Max

Whether to limit CPU usage, find & delete duplicate files or uninstall pre-loaded apps, many of us have used the PowerShell tool at least once on our Windows PC.

But what exactly is this Windows PowerShell & do we need it?windows-powershell-101

Let’s find out together.

What is Windows PowerShell?

Before we can elaborately define Windows PowerShell, first, we need to know what the term Shell means. A Shell is a computer program that acts as an interface between a user and the OS.

This interface takes commands through the computer’s user input(keyboard/mouse/controller etc), interprets them & sends the commands to the OS for execution. It can either be a graphics-based user interface(GUI) or a command-line-based interface/dialogue box.

Windows PowerShell is an open-source, cross-platform task automation tool that is based on command-line interface(CLI). Basically, it’s a dialogue box that allows users to carry out different system-level tasks or functions by inputting specific command lines.

Released by Microsoft, PowerShell is built on top of a scripting language, a command-line shell, .NET common language runtime(CLR) and a configuration management framework tailored for system administrators.

It’s usually considered a powerful tool for simplifying configuration and performing any user defined system-level functionality on Windows, Linux, or MacOS.

Windows PowerShell allows users to access the file system and other data stores, such as the registry and digital signature certificate. It also lets you perform various operations, from automating repetitive tasks to network administration, and so on.

Here are the Windows PowerShell versions:

  • PowerShell 1.0
  • PowerShell 2.0
  • PowerShell 3.0
  • PowerShell 4.0
  • PowerShell 5.0
  • PowerShell 5.1
  • PowerShell Core 6.0
  • PowerShell Core 6.1
  • PowerShell Core 6.2
  • PowerShell 7.0
  • PowerShell 7.1
  • PowerShell 7.2

PowerShell 7 is currently the latest version of this command line tool. You can easily download the latest PowerShell for your computer by following the link.

What is a PowerShell Cmdlet?

The Cmdlet(pronounced as command-let) is a noteworthy aspect of Windows PowerShell. Cmdlets are essentially light and ubiquitous PowerShell commands that can be used to perform certain actions such as reading files, pinging a computer, removing a registry key, & a lot more.

These binary commands act as building blocks to build a bigger, more complex PowerShell script.

For example, the Get-Help Cmdlet allows users to see what a specific Cmdlet does, along with its parameters and how that Cmdlet can be used. get-help-cmdlet

Get-Command is another one that lets you troubleshoot different system-level issues from PowerShell. To be precise, this Cmdlet shows you all the commands installed on your system, including their functions, aliases, filters, scripts, and applications.

The latest PowerShell version(PowerShell 7) ships with more than 1500 compiled Cmdlets.

Key Features of Windows PowerShell

Let’s take a look at some of the key features of Windows PowerShell to determine what this command tool can do for you.

1. Discoverability of Commands and Parameter Aliases

You can use the Get-Command Cmdlet to discover the PowerShell features. It’ll give you a list of all commands available on your computer. You can also set parameters to narrow the search.

Furthermore, the Get-Item Cmdlet allows users to find a specific file or directory of their computer. By using the wildcard character(*), you can request all the contents of an item at a specific location.

2. In-console Help System

The Get-Help Cmdlet can be used to learn more about PowerShell principles and its components. You can also use the online parameter to access help articles for a specific topic on the web.

3. Remote Command

The PowerShell can be used by admins to perform remote actions on one or more computers and take advantage of technologies such as Windows Management Instrumentation & WS-Management.

Users can run PowerShell commands and scripts on remote computers via the WS-Management protocol.

4. Pipeline for Chaining Commands

By using PowerShell’s pipe operator feature, symbolized by |, commands can be linked together to create a chain command. This feature turns the output from a given command into input for the next command, making a flow from one Cmdlet to another in a pipeline sequence.

PowerShell also boasts some additional features like the ability to accept and return .NET objects(unlike other shells that can only accept and return text), tab completion & command prediction to provide ease for developers, resource configuration, etc.

How to Launch the Windows PowerShell

Every Windows OS comes with a built-in PowerShell tool that can be used for various scenarios. Launching the PowerShell tool on different platforms requires different methods.

Here are the steps to launch PowerShell:

On Windows

  • Press Start and type powershell.
  • Right-click on Windows PowerShell.
  • Select Run as administrator. launch-windows-powershell

On Linux

  • Press Ctrl+Alt+T to open the terminal.
  • Type pwsh and hit the Enter button.

Windows users can alternatively use the Run dialogue to launch PowerShell. Simply press the Windows Key+R and type powershell. Then press Enter.

How to Use Windows PowerShell

As mentioned above, Windows PowerShell is a useful admin tool that lets you perform various system-level tasks quite effortlessly. Below, I have shortlisted some of its use cases that might come in handy for a lot of users.

1. Running Commands on Remote Computer

One of the most noteworthy aspects of Windows PowerShell is the ability to remotely execute commands on one or multiple computers by network admins. To do this, all you need is a PC and reliable internet access.

But first, you’ll need to establish a remote connection between your PC and the targeted computer(s). The following PSSession command can be used for this purpose: Enter-PSSession -ComputerName RemotePCName -Credential UserID

After you’ve established a stable connection between the targeted computers, simply input any PowerShell commands as you’d do on a local system and hit Enter to execute them on the remote computers.

For example, type Invoke-Command -ComputerName Server01, Server02 -FilePath c:\Scripts\DiskCollect.ps1 on your computer’s PowerShell dialogue box and press Enter. It will execute the DiskCollect.ps1 script on the server01 and server02 remote PCs.

You can learn more about remote commands from Microsoft’s official PS command guide.

2. Deleting Contents from a Specific File

Another useful aspect of the PowerShell tool is being able to easily delete all old contents from a file, but keeping the file itself intact. The syntax for this Cmdlet is Clear-Content<enter your file path with its extension>

For instance, type Clear-Content C:\Users\user\Desktop\TempFile.txt and hit Enter. It will clear all texts from the .TXT file but keep the main file intact.

Furthermore, via the Get-Content PowerShell Cmdlet, you can see the content of an item or part of a file. Type the command like Get-Content<PATH of the file with its extension>.

3. Making Scripts Using PowerShell

A script is basically a short program, containing a sequence of instructions, that can be carried out by another, bigger program during its execution. With Windows PowerShell, users can easily create and execute various scripts to perform certain automated tasks.

There are many ways to create a PowerShell script. I’d recommend using Notepad as it’s the quickest and easiest way to make a PS(PowerShell) script.

But before you start, keep in mind, you need to run the Windows PowerShell as admin. Otherwise, you won’t be able to change the execution policy to run scripts through PowerShell.

Follow these steps to create and execute scripts on PowerShell:

  • Press Windows key+S and type notepad.
  • Hit Enter.windows-notepad
  • Type Write-Host “<enter your text>”. For example, Write-Host “Hakuna Matata; It Means No Worries.”.
  • Click on the File option from the top left corner of the screen.
  • Select Save as. notepad-script
  • Enter your preferred name(I have named it script) and hit Save.script-save
  • Press Start and type powershell.
  • Right-click on Windows PowerShell and select Run as administrator. launch-windows-powershell
  • Type the following command and press Enter: Set-ExecutionPolicy RemoteSigned. It’ll alter the execution policy of your PC to run scripts with PowerShell.
  • Press A, then hit the Enter button on your keyboard.
  • Input the following command to run the script: & “<enter the file path of your script with extension>”. For me, it’s & “C:\Users\user\Desktop\script.txt”.
  • Hit the Enter button. powershell-script

4. Managing Files and Folders

With the help of PowerShell, users can easily manage their computer’s files and folders directly from the PS dialogue box. Various actions can be taken to tinker with the files and folders by using specific PS commands. Here are some examples:

Opening Files

Input the following command to open a file from the targeted folder: Invoke-Item <path of the file with its extension>. For example: Invoke-Item C:\Users\user\Desktop\script.txt.

Additionally, you can open multiple files by slightly adjusting the command syntax. Use asterisks(*) instead of a specific file name to open all the files in the targeted folder. I.e: Invoke-Item C:\Users\user\Desktop\*.

Moving Files and Folders

Use the Move-Item Cmdlet to quickly move your computer’s files and folders from one directory to another. Type Move-Item <enter your file’s current path with its extension> <enter the path where you want to move the file> and press the Enter button.

Renaming Files and Folders

Just like moving files and folders, you can use PowerShell commands to rename a specific file or folder’s name. The Cmdlet to perform this action is Rename-Item.

Simply run the PowerShell tool as an admin and type Rename-Item <path of the file with its extension> <new file name with its extension>.

5. Running a Malware Scan Via PowerShell

You can even run a malware scan on your device using Windows PowerShell’s Start-MpScan Cmdlet. Not to mention, it also allows users to run either a quick scan or a full scan depending on their needs.

To run a quick scan, type the following command: Start-MpScan -ScanType QuickScan

To run a full scan, type the following command: Start-MpScan -ScanType FullScan

Since a full malware scan can take several minutes, you can run the scan in the background by using this command: Start-MpScan -ScanType FullScan -AsJob

You can also check the CPU usage using PowerShell.

PowerShell Vs Command Prompt(CMD)

Command Prompt and PowerShell may look very similar at a first glance. But there are many notable differences between the two command-line interfaces.

The biggest difference between PowerShell and CMD is the extensibility. The inputs and feature sets of PowerShell are immensely vast compared to Command Prompt. PowerShell is basically an advanced version of CMD.

Secondly, PowerShell supports .NET runtime framework, but Command Prompt doesn’t. As a result, PowerShell can accept and return .NET objects while CMD can only accept and return text.

These are some additional differences between PowerShell and Command Prompt:

PowerShellCommand Prompt
Works with both batch commands and cmdlets.Only works with batch commands.
Let users create scripts and aliases for cmdlets.Can’t create aliases for commands.
Ability to pipeline sequence multiple commands.Can’t create pipeline sequence of multiple commands.
Can integrate directly with WMINeeds external plugin for WMI integration

In conclusion, unlike the Command Prompt, Windows PowerShell isn’t just a shell. It’s a robust scripting environment that allows users to create complex scripts. These scripts can be used to manage the Windows OS much more easily than you can with CMD.

Frequently Asked Questions

Does Windows PowerShell run in the background?

No. Windows PowerShell usually doesn’t run in the background unless you’ve set a background job command.

Is it OK to disable Windows PowerShell?

Yes. Disabling Windows PowerShell is completely fine as it’s not a requirement to properly run Windows OS.

Is PowerShell the same as the command prompt?

No. PowerShell is not the same as the Command Prompt as the first one is extensive while the other one is limited as an interpreter.

Ending Note

That’s all for today. Be very cautious when you enter a command line in the PowerShell as a wrong command can potentially cause harm and instability to the system.

Anyway, I hope this write-up has provided everything you wanted to know about the PowerShell feature. If you still have any further questions on this topic, feel free to share your thoughts in the comment section below.

Adios!

About The Author
Farhan Max is a tech geek with a particular interest in computer hardware. He's been fascinated by gaming since childhood and is now completing his undergraduate studies while researching and testing the latest tech innovations. Alongside his love for all things geeky, Farhan is also a skilled photographer.

Leave a Comment