Getting Started with PowerShell

What is PowerShell?

PowerShell is a powerful object-based scripting language that was developed by Microsoft for the Windows operating system. It is built on the .Net CLR (Common Language Runtime), and was created for the purpose of Windows administration and automation. There are currently two main branches of PowerShell: Windows PowerShell and PowerShell Core.

Windows PowerShell

Windows PowerShell is the branch of PowerShell that was first introduced in 2006. It is only compatible with Microsoft Windows operating systems and runs on the full .Net Framework. It has versions from 1.0-5.1, with 5.1 being the final version. This branch will continue to receive security and break/fix releases, but it is considered a finalized product by Microsoft. Therefore, it will not be receiving any further feature updates. This does not mean that it is deprecated or out of support, as Microsoft’s intention is for Windows PowerShell to be the scripting language of choice for Windows for many years to come.

Starting with Windows 7 SP1 and Windows Server 2008 R2 SP1, Windows PowerShell is shipped with Windows in various versions. The compatibility matrix located here shows compatibility for PowerShell versions and Windows operating systems in addition to which versions of PowerShell ship with different versions of Windows operating systems.

For our Windows VPS products, it is highly recommended to install the most up-to-date version of Windows Powershell (5.1). This will require .Net Framework 4.5.2 or newer.

Windows Management Framework 5.1 Download Page

PowerShell Core

PowerShell Core is a cross-platform, open-source branch of PowerShell that runs on .Net Core. It is compatible with any operating system that supports .Net Core. It has less functionality than Windows PowerShell as it does not have the full .Net runtime, but it is still very full-featured, and is the branch that receives continued development from the open-source community. Please see the below links for installation instructions on Windows, Linux, and macOS, and ARM.

Determine Which Version is Installed

You can determine which version and/or edition of PowerShell is installed by launching Windows Powershell (powershell.exe) or Powershell Core (pwsh.exe) and running the below code:

$PsVersionTable

This will output the PSVersion property and the PSEdition property. The PSEdition property will either be Desktop (Windows PowerShell) or Core (PowerShell Core), and the PSVersion property is the version number of whichever edition is installed.

Using Windows PowerShell

To launch the Windows PowerShell console, you can either: run (Windows Key+R) “powershell” and click OK or press Enter, search for PowerShell from the Start Menu, or for Server 2012 and up, open the Quick Link menu by either right-clicking the Start Menu or pressing Windows Key+X, and then choose PowerShell from the menu.

To make the Windows Key+X menu show PowerShell instead of cmd on your Windows 2012 or newer VPS, please follow the following instructions based on which version of Windows you are running.

  1. Go to the Start Menu, then Settings
  2. Search for PowerShell
  3. Check the option to replace Command Prompt with Windows PowerShell

Windows 8 or 8.1/Server 2012 or 2012 R2

  1. Right-click the taskbar
  2. Click “Properties”
  3. Choose the Navigation tab, then check the option to replace Command Prompt with Windows PowerShell
  4. Click “OK”

In addition to the console, Windows PowerShell also includes an IDE called PowerShell ISE. This can be opened from the Start Menu or by running (Windows Key+R) “powershell_ise”. This IDE includes syntax highlighting, autocompletion, and more. Another popular PowerShell IDE is Visual Studio Code.

Below is sample PowerShell code that reads a name, and then says “Hello”.

$Name = Read-Host "Please type your name here"
Write-Output "Hello, $Name"

PowerShell Resources

The below links are some examples of valuable resources for learning the PowerShell language.