PowerShell is a task automation and configuration management framework released by the Microsoft Corporation in 2006. It consists of the PowerShell command-line shell and an associated PowerShell scripting language.

What is PowerShell?

This article refers to the command line interpreter PowerShell, for information about the Scripting Language, please visit the Scripting Category of the lexicon.

In computer science, a shell is the software by which a user interacts with an operating system – a human-machine interface. PowerShell offers SysAdmins and IT professionals the option to automatize, control and regulate tasks or processes of operating processes.

Other known or popular shells to name are Windows Explorer, Microsoft Management Console, Windows control panel, cmd.exe or Bash (Unix). Usually they are differentiated by their appearance, a command-line interface (CLI) is a text-based user interface, whereas a graphical user interface (GUI) allows interaction via a graphical icon or audio.

Definition

PowerShell is the main command-line interface for Windows environments. It has been developed with the use of .NET Framework and functions as a Dynamic Link Library (DLL). In order to run it, the use of a host application is mandatory, where runspaces can be defined and sessions run or opened. The user interacts within a command-line interface.

The execution of a PowerShell command works as follows: the host application sends a command to the Windows PowerShell Engine (DLL), where it will be processed and given back to the host application as an object, which will then appear in a text format. By knowing that, it might be unsurprising that the text output may not contain all the information of the former object.

Since the release of PowerShell Core in 2016, based on the .NET Core Common Language Runtime (CoreCLR), PowerShell runs as a cross-platform and open-source project with the MIT-license on Linux, macOS and Windows.

Typical use cases

Use cases for PowerShell can mainly be found in administration, automation and configuration.

PowerShell is usually used by sysadmins to facilitate complex processes or automate reoccurring tasks via scheduled jobs. It also offers power-users a variety of services and automation options.

The main core question one should ask oneself should be: “How often should I perform a certain action?” and “How long does it take me, to do the task manually?”. If the answer to this is something along the lines of “Constantly” and “Very long”, PowerShell might be a good solution for you.

For many automated tasks, PowerShell already offers several types of jobs: background jobs, remote jobs, scheduled jobs and workflow jobs, each with a different feature.

Also, manufacturers like ScriptRunner offers so-called ActionPacks with ready-to-use PowerShell scripts, giving you a head start with the problem of “when to start?”.

PowerShell compared to other command-line tools

PowerShell vs. CMD

Windows command-line prompt – or simply CMD – has been the de-facto standard shell for Windows for years but was officially replaced by PowerShell in 2017.

The main difference between PowerShell and CMD can be broken down quickly: CMD is a string while PowerShell is object-orientated, both having all characteristics of the given types.

Due to it being built using .NET Framework, PowerShell has direct access to all the .NET libraries, empowering it to call external programs, as opposed to CMD. When an external program is called by CMD, it passes the file name and arguments over to Windows itself via the ShellExecuteEx API call.

The integration of PowerShell can be done at runtime and it is capable of running a bunch of different programs, producing a variety of text objects, CMD only returns text output of the consoles program type. To sum it up, there will be no function existent executed by CMD that PowerShell isn’t capable of.

PowerShell additionally offers a ton of additional features with its cmdlets, pipes and scripts. Before its market launch a sysadmin had to scroll manually through all commands via the GUI without any simple alternative to iterate a certain command without the doubled amount of expense.

PowerShell vs. Bash

Bash was developed as a Linux-Shell for being used in a developer environment, adding and supporting CLI-based interaction. One must distinguish between Bash on Linux and Windows. The following is valid for Bash under Windows.

Bash uses texts as in- and output, making it simple for users to pass information among programs. PowerShell instead uses pipelines of interconnected objects for transferring complex data and whole data structures within a pipeline.

In addition, PowerShell also serves as a perfect tool for configuration under Windows, e.g. changing the registry or managing the Azure Cloud in Exchange. Bash only functions via APIs, which works great for processing text data, but doesn’t facilitate texts as data itself.

On a Linux OS Bash offers a whole ecosystem though, with subshells and login-shells. One can conclude that PowerShell is the main scripting language once one wants to work with a network of Windows systems and Bash under Windows offers a thought-out approach for creating a scripting environment to extend and add Linux-Code, whereas on GNU/Linux systems it is a replacement.

PowerShell versions

How to check for the PowerShell version

The fail-safe command for finding out which PowerShell version is installed on a system is the following:

$PSVersionTable.PSVersion

Upon not showing a variable one can conclude the engine version is “1.0”.

One common mistake while determining the installed version is using the commands “$Host.Version” and “(Get-Host).Version”. These cmdlets will only reveal the host version, not the engine version.

Overview of PowerShell versions and features

Installation

PowerShell is pre-installed on Windows, so one might want to check the table above for the version that Windows has already come with.

Microsoft completely reshaped its former Windows-exclusive management framework tool to serve on a broad range of operating systems

The recommended way to find supported platforms or versions is the official GitHub PowerShell Repository, even including installing instructions or find PowerShell versions for community-supported platforms only.