Four PowerShell Critical Prerequisites

by Nov 19, 2021

If you are switching to a new computer, you may want to do a quick sanity check to see if PowerShell is set up correctly. Here are four things you should definitely check:

1 Check PowerShell Version
Run $PSVersionTable to check your PowerShell version.

 
PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
 

Since $PSVersionTable is a hash table, you can also convert it to an object to select certain properties:

 
PS> [PSCustomObject]$PSVersionTable | Select-Object -Property PSVersion, PSEdition

PSVersion      PSEdition
---------      ---------
5.1.19041.1237 Desktop  
 

If “PSEdition” is “Desktop”, then you are using the built-in Windows PowerShell. It should be version 5.1. Any older version is deprecated, and using older versions may induce security risks. Since Windows PowerShell is feature-complete, there are no new versions beyond 5.1.

If “PSEdition” is “Core”, then you are using the new platform-independent PowerShell. The current version is 7.1.5, and there are frequent updates.

2 Check Execution Policy
PowerShell makes no sense if you can’t run scripts. The execution policy should be set to “RemoteSigned” (only local scripts allowed) or “Bypass” (scripts located anywhere can run, including downloaded scripts):

 
PS> Get-ExecutionPolicy
Bypass
 

Use this to change the execution policy if needed:

 
PS> Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force 
 

3 Check PowerShellGet
PowerShellGet is an important add-on because it represents the PowerShell package management. With PowerShellGet, you can install additional modules via Install-Module. If this module is out-dated, you may no longer be able to download and install additional modules:

 
PS> Get-Module -Name PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 -Property Version

Version
-------
2.2.5 
 

If the reported version is less than 2.2.0, you need to update this module. This is especially true if you see version 1.0.0 or 1.0.1 (the initial module that originally shipped with Windows and was never since updated).

To update the module, you need to reinstall it along with its prerequisite PackageManagement module:

Install-Module -Name PowerShellGet -Scope CurrentUser -Force -AllowClobber
Install-Module -Name Packagemanagement -Scope CurrentUser -Force -AllowClobber

4 TLS Support for 1.2
A final thing to check is whether Windows is setup to support the transport layer protocol 1.2:

 
PS> ([System.Net.ServicePointManager]::SecurityProtocol -band 'Tls12') -eq 'Tls12'
True 
 

If this is $false, then your Windows still uses outdated settings, and PowerShell may not be able to connect to HTTPS: webservices and sites. You should update Windows. Meanwhile, you can manually enable TLS 1.2 on a per-application setting:

[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor
[System.Net.SecurityProtocolType]::Tls12


Twitter This Tip! ReTweet this Tip!