Installation and Update
Compatibility
Pester is a cross-platform module that runs on Windows, Linux, MacOS and anywhere else supported by PowerShell. It is tested and compatible with:
- Windows PowerShell 3.0 - 5.1
- PowerShell 6.0.4 and above
Installing from PowerShell Gallery
You can install Pester using the built-in Install-Module
command. The examples below will install Pester in your default installation scope depending on your PowerShell-version. You can control this using the -Scope <AllUsers/CurrentUser>
parameter.
Linux & MacOS
From a PowerShell session run:
Install-Module -Name Pester
To update:
Update-Module -Name Pester
Windows
Windows 10 / Windows Server 2016 and later ships with Pester version 3.4.0. This built-in version cannot be updated using the simple Update-Module
cmdlet.
Instead you need to perform a side-by-side installation to get started with the latest version of Pester.
The built-in version is signed by Microsoft while newer versions are community-maintained and signed with a different certificate,
causing Install-Module
to sometimes throw a error requiring us to accept the new publisher certificate.
Run the command below to install the latest version:
# -Force to install side-by-side
# -SkipPublisherCheck to accept the newer certificate
Install-Module -Name Pester -Force -SkipPublisherCheck
For any subsequent updates it is enough to run:
Update-Module -Name Pester
If you'd like to remove the built-in version of Pester, you can do so using the following code as administrator:
$module = "C:\Program Files\WindowsPowerShell\Modules\Pester"
& takeown.exe /F $module /A /R
& icacls.exe $module /reset
& icacls.exe $module /grant "*S-1-5-32-544:F" /inheritance:d /T
Remove-Item -Path $module -Recurse -Force -Confirm:$false
# Install latest Pester
Install-Module -Name Pester
Common errors
TLS error while connecting to PowerShell Gallery
If you receive the following warning when trying to install the module, you may need to explicitly enable TLS 1.2.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
# Enable TLS 1.2 for the current PowerShell instance using the line below and try again
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12
Command Install-Module
is not found
Older versions of Windows running Windows PowerShell 3.0 or 4.0 do not have a built-in package manager. You can install PowerShellGet
using the instructions here. After completing the steps, start a new PowerShell session and retry the module installation.
Alternatively, you can install the module manually using the instructions below.
Installing manually
You don't have to use a package manager to install Pester. Another option is to download and installing it manually which can be useful in e.g. offline environments.
- Download the module on a machine with internet using either:
Save-Module -Name Pester -Path C:\Temp
. It will save it in a versioned folder, ex C:\Temp\Pester\5.5.0- Or download the NuGet package from PowerShell Gallery and extract it, see Manual Package Download
- Copy the Pester-folder (ex. C:\Temp\Pester) to your destination computer and place it in one of your module directories defined by $env:PSModulePath. On a Windows-system the default locations include:
- Current user: $HOME\Documents\WindowsPowerShell\Modules
- All users: $env:ProgramFiles\WindowsPowerShell\Modules
- Start PowerShell and start testing.
Step 2 is an optional step to enable simple import by name and module auto-loading. You could also import Pester using an absolute path like Import-Module C:\Temp\Pester\5.5.0
.
Alternative package sources
PSGallery is the easiest way to get Pester installed to your computer, but there are alternatives. On a build server you might prefer using Chocolatey, or if you're adding Pester to your .NET project that already uses NuGet you might prefer that.
These options may not support pre-release versions and it may need to be initialized on first use.
Chocolatey
Chocolatey (or choco) is a commonly used package manager for Windows. You can install Pester using:
choco install Pester
Or to update:
choco upgrade Pester
You may also pass the --prerelease
option to install or update to a prerelease version of Pester.
Nuget
Nuget is the package manager for .NET projects. Getting Pester from Nuget is useful when you are integrating PowerShell code with your .NET project, and want to have that code tested.
To install use Package Manager of Visual Studio, or Package Manager Console in Visual Studio. Once you need this we are pretty sure you know what you are doing. 🙂