Skip to the main content.

PowerShell command-line shell

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?”.

Visit our use cases gallery for more examples on what IT Admins and DevOps professionals can achieve with PowerShell.

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

Compatibility:

Windows XP SP2, Windows Server 2003 SP1, Windows Vista

Features:
  • Core functions established
  • Pipe function
  • Script language existent
  • cmdlets developed in .NET
  • Basic console
Compatibility:
  • Windows 7
  • Windows Server 2008 R2
  • Windows XP Service Pack 3
  • Windows Server 2003 Service Pack 2
  • Windows Vista Service Pack 1
Features:
  • 240 cmdlets and new operators added
  • With WS-Management scripts and cmdlets can be invoked on remote machine(s),
  • PSJobs (background jobs) possible
  • Transactional operations available
  • Advanced functions (formerly known as: “script cmdlets”)
  • Stepable pipelines
  • Modules have been added
  • Data language changes, featuring help messages for scripts and functions in the user’s UI language (script internationalization)
  • Script debugging with setable breakpoints
  • Eventing available, with terminability of managed entities of the user and notification of state changes
  • PowerShell Integrated Scripting Environment (ISE) introduced and implemented
  • Network file transfer with native prioritization
  • New API functions
Compatibility:
  • Windows 8
  • Windows Server 2012
  • Windows 7 Service Pack 1
  • Windows Server 2008 R2 Service Pack 
Features:
  • Scheduled jobs
  • Sessions can be disconnected and reconnected
  • IntelliSense (Code completion) & snippets added
  • Delegation support
  • Help updates
  • Automatic module detection, inserting a module automatically upon invoking a command from the module
  • Multiple new commands and modules
Compatibility:
  • Windows 8.1
  • Windows Server 2012 R2
  • Windows 7 SP1
  • Windows Server 2008 R2
Features:
  • Desired state configuration via WS-Management protocol
  • New default execution policy: RemoteSigned
  • Save-help implemented
  • Enhanced debugging with debugged workflows, remote script execution and preserving debugging sessions
  • Network diagnostics
Compatibility:
  • Windows Management Framework (WMF)
Features:
  • PowerShell class definitions (properties, methods)
  • PowerShell .NET Enumerations
  • Debugging for PowerShell Runspaces & Background Jobs
  • Desired State Configuration (DSC) and Local Configuration Manager (LCM) version 2.0
  • DSC partial configurations and DSC LCM meta-configurations
  • Authoring of DSC resources via PowerShell classes
Compatibility:
  • Crossplatform & Windows-independent
  • Free & open source
Features:
  • Major change: platform expansion and open-source
Compatibility:
  • Support for latest Windows, macOS and Linux versions
Features:
  • Increased cmdlet compatibility
  • Performance gain
  • Based on .NET Core 2.1
  • Markdown cmdlets

Features:

  • Performance improvements
  • Bug fixes
  • Minor cmdlet/language enhancements

Features:

  • Based on .NET Core 3.1
  • Available across Windows, Linux and MacOS platforms
  • Works not only locally, but also in the cloud and in hybrid infrastructures
  • Intended as a replacement for Core 6.x products and Windows PowerShell 5.1
  • SSH as new network protocol for PowerShell remoting
  • New ternary operator “a ? b : c” for formulating „if–else“- statements
  • New pipeline chain operators „&&“ and „||“ for linking multiple pipelines conditionally
  • New NULL Condition Operators „??“ and „??=“ for performing conditional queries
  • New feature „ForEach-Object -Parallel“ for the parallel processing of objects in a pipeline
  • New option „ConciseView“ and „Get-Error“ Cmdlet for improved error handling

For a detailed overview of what’s new in PowerShell version 7, we suggest you read the article Welcome to PowerShell 7 on the ScriptRunner Blog.

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.