Powershell

Table of Contents

Setup Shell

Per previous page, starting PowerShell can be started from the start menu of any Windows 7, 8, 8.1 or 10 operating systems. Before proceeding further you should know there are 7 versions of PowerShell 1 - 7.

When PowerShell was first created by the Microsoft team for the Windows operating system, version 1 in 2006. The functionality of PowersShell was very limited in the commands it could do

subsequently Microsoft have worked on Microsoft till this date providing a large functionality of commands and modules that anyone can use to virtually interact with any modern device.

The different versions of PowerShell and their release dates are below


Notes

PowerShell ISE - The PowerShell team have stopped developing ISE because the edit text area with syntax highlighting and everything was a control from the Visual Studio team, and they couldn't get approval to make that open source, cross platform, with the VS team committing to support all kinds of new use cases, so they started rebuilding as VS Code

Source: Bruce Payette "Historical Architecture Tour of PowerShell" talk video

The official Microsoft recomendation between ISE and Visual Studio Code useage is “We do recommend using VSCode over the ISE whenever possible since it is the recommended tool by Microsoft.”

Version Year Notes
Powershell 1.0 2006
Powershell 2.0 2009
Powershell 3.0 2012
Powershell 4.0 2013
Powershell 5.0 2016
Powershell 6.0 Core 2017 Was considered a problematic release as it had reduced amount of commands due to multi OS support requirements of some commands not working on certain operating systems.
Powershell 7.0 TBA - Preview release available for download Will attempt to address re-adding dropped commands from PowerShell 6 as well as be multi-OS orientated.


Continue along by typing the below into the PowerShell ISE shell in the blue bottom pane and pressing the <Enter> Key

get-command




As you can see in the output of the command (Will from now on be referred to cmdlet as per proper nomenclature) when the Get-Command command is run, it lists an output of all the cmdlets of Powershell native shell language. The output of the first command is then outputted (will be referred to as Piped as indicated by the vertical bar "|" special character) to a second cmdlet "Sort-Object" that sorts the output of the first objects contents (The commands) based on the parameter specified (Version).

Its alot of information to process but think of it this way. A command, as indicated by a verb-noun grammar is a programming function that does "something" that is whatever it was programmed to do. In this case the cmdlets below each to a specific task;

Get-Command
Looks in the PowerShell shell installed on your computer and lists all the cmdlets (Programming functions) that are available. The newer versions of PowerShellPowerShell that are installed through Microsoft updates have more cmdlets then their predecessors.

Sort-Object
The sort object cmdlet takes an input of an cmdlet and outputs it based on the criteria. It cannot be run by itself.

As daunting as it seems. PowerShell is very simple in nature. First find the command you are requiring to do a specific task and see whether it is available in your version of PowerShell. Then run it by starting the PowerShell shell (Program) and type the command and hit enter.

Check current PowerShell version


As Powershell ages, some cmdlets become redundant and replaced with more appropriate cmdlets. It is best to keep Powershell updated to the latest version if you are wanting to learn best practice. This site assumes you are running on a personal device or at least a test VM. To determine the existing version of Powershell you may run this command

$psversiontable




The dollar sign special ($) special character represents an variable. e.g. A stored value. The cmdlet when run looks into the variable as defined by dollar sign ($) and displays the contents.

What we are interested in is the PSVersion property value: 5.1. This represents that Powershell version 5 is installed build 1. But we are only interested in the first digit which represents the main version (5).

The default version of Powershell insalled/Available on each OS is below.

Note: Since 2017, Microsoft has released Powershell version 6.0 Core on Mac and Linux OS's. Version 6.0 Core is currently a limited shell that can be installed as a third party software only on both aformentioned operating systems.

Although due to the nature of cmdlets being inhenetly designed for Windows OS the full cmdlets are not yet available for Powershell 6.0. This remains yet to be seen if Microsoft will continue in the future to support other OS. It is still worth trying to install Powershell on either of these OS's as the remoting capability can help in day to day system administration.

Operating System Version
Windows Server 2008 1.0
Windows 7 2.0
Windows Server 2008 R2 2.0
Windows 8 3.0
Windows Server 2012 3.0
Windows 8.1 4.0
Windows Server 2012 R2 4.0
Windows 10 5.0
Windows 10 Anniversary Update 5.1
Windows Server 2016 5.1
macOS 10.12+ 6.0
RHEL 7+ 6.0
CentOS 7+ 6.0
Oracle Linux 7+ 6.0
Debian 8.7+ 6.0
Ubuntu 14.04+ 6.0


Installing PowerShell Core on MacOS

PowerShell for MacOS isn't install by default, instead Microsoft releases all versions/releases of PowerShell on their GitHub Repository page the user can then start the Terminal application on their Mac, and run the Git commands to copy over a version/release of PowerShell from the GitHub repository onto their local harddrive and install. PowerShell Core supports macOS 10.12 and higher. After the package is installed you will need to run the 'pwsh' command from macOS app 'Terminal' to start PowerShell.



Full installation steps of installing PowerShell Core on MacOS may be found here

PS for MacOS doesn't have its own CLI program and instead relies on Mac Terminal to run. The commands in PowerShell Core are also limited to the Mac Operating system. Commands run in Windows use the native DLL's & assemblies to run functions against the Windows OS and ouput into the runtime engine CLI PowerShell. With PowerShell Core, the commands availabel are limited to the functions that can be run against MacOS.

For many MacOS Admins, the above reason alone is why many Admins choose to use Python for System Administration as the Python programming language comes preinstalled in newer versions of MacOS and has much thirdparty support to map out the core components of MacOS to run commands against.

Upgrading | Updating Powershell

Installing Powershell has never been easier. It requires only the Operating System being capable to support the latest version of Powershell. and that .Net Framework software be installed on your computer.

If you find that your version of Powershell is below version 5. to follow along with the remainder of this website and to be up to date perform the below tasks.


Installing PowerShell 5

Prerequisites: Internet connection

1) .Net Framework 4.5.2 - be the only .net framework install in add or remove programs
You can install .Net framework 4.5.2 for Windows from the following URL https://www.microsoft.com/en-au/download/details.aspx?id=42642
2) Once .Net 4.5.2 is installed then start Powershell (non ISE) as administrator by searching in start menu and right clicking on Powershell and and clicking run as.

3)Then copy and paste the below command into your shell and press the enter key. As the installation starts, press the Y key when prompted to continue until completion.

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install powershell -y
choco upgrade powershell –y


Once completed restart the computer. Turn the device back on, and type
$psversiontable
To determine whether you now have version 5 of Powershell installed and are ready to get started programming.

Visit next page to learn about - Getting Help