PowerShell – my spell checker keeps trying to correct my spelling to “Powers Hell” and for some this might be a more accurate description, but what is it’s history?
PowerShell is a useful and helpful task automation and configuration framework consisting of a scripting language and command line shell. It is for all intents and purposes the windows version of Bash from Unix (and more recently Linux).
The first iteration released only as a Release Candidate version occurred in 2006. The first version that shipped widely built into any of microsoft’s operating systems was Version 2, which shipped three years later in 2009 with Windows 7 and Windows Server 200 R2, other versions for earlier operating systems were made available but as a separate download.
The command line interface is a separate and standalone executable. It can execute any of the builtin cmdlets (built-in commands that ship with the framework), user written scripts, or other executable files and has all (maybe most) of the characteristics that one would expect in a modern command shell.
Host Applications
As mentioned in the previous section PowerShell is a command line shell, but it also ships with an Integrated Scripting Environment. To confuse matters even further it comes with both 64 and 32 bit versions of both. There are now a variety of third party apps that have support for PowerShell including the cross platform VScode and Sublime Text editor
The advice of the author is to find an editor that works for you. The ISE and VScode are not from Microsoft and both have Intellisense that tries to help you and pre-empt what you are typing. It’s worth noting that if you use the the 32bit versions Intellisense isn’t available.
Version History
There are seven major versions of PowerShell
Version 1
- Downloadable for XP SP2 and Server 2003
Version 2
- Integrated into Windows 7 and Server 2008 R2
- Downloadable for XP SP3, Server 2003 SP2 and Vista SP1
Version 3
- Integrated with Windows 8 and Server 2012
- Downloadable for Windows 7 SP1, Server 2008 SP1 and Server 2008 R2 SP1
Version 4
- Integrated into Windows 8.1 and Server 2012 R2
- Downloadable for Windows 7 SP1, Server 2008 R2 SP1 and Windows Server 2012
Version 5.1
Integrated into Windows 10 and Server 2016 and 2019
Downloadable for Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, and Windows Server 2012 R2
There are two editions of this versions, a full desktop version and a cut down “Core” version which has limited functionality, The Core version has no cmdlets to manage the clipboard, WMI (v1), event logs or profiles.
Version 6
This is a completely new version of PowerShell. Known as PowerShell Core, it is open source and cross platform but contains no new features for Windows administration and so was not widely adopted by Windows administrators. It has been adopted by some that use other platforms such as Linux and MacOS
Version 7
This is the first truly cross-platform version that is a viable replacement for 5.1. It is more compatible with established Powershell modules and delivered some new functionality for the first time in nearly four years. It is a separate executable and Versions 5.1 and 7.x can be installed in parallel on the same device.
Multi Version Environments
If you are working in a multi version environment, which is most likely if you have a variety of older and newer operating systems, you will need to be able to identify the version on the host you are working or on which you want you code to run you can establish this by opening either the command shell or the ISE and issuing this command
$PSVersionTable
If you have a specific development machine, you can install multiple versions side by side and then tell PowerShell which version to use by issuing the command
PowerShell.exe -Version <version no>
Remember though that in doing so you may be losing security enhancements that were delivered in later versions and that whilst this does tell PowerShell which engine to use, it may not deliver 100% compatibility and what you see in a newer version may not be available in an older one. Upgrading PowerShell to a newer version should be the target operating model wherever possible, although currently for most enterprises 5.1 is still the dominant version as 6.x lacked compatibility with third party modules and 7.x is an optional download many just don’t have time for.