Installation and Update
Compatibility
Pester is compatible with every version of Windows that can run at least PowerShell 3. That includes: Windows 10, 8, 7, Vista, and their respective Server versions 2016, 2012 R2, 2012, 2008 R2 and 2008.
Installing from PSGallery on Windows 10 or Windows Server 2016
Windows 10 and Windows Server 2016 make installing and updating PowerShell modules extremely simple by providing Install-Module
and Update-Module
cmdlets.
Unfortunately there are some complications specific to Pester that we cannot avoid.
Pester version 3.4.0 ships as part of Windows 10 and Windows server 2016, and that distribution conflicts with the standard module update mechanism.
It is not possible to update the built-in Pester to a newer version, using the Update-Module
cmdlet.
Instead you need to perform a new side-by-side installation of Pester, because Install-Module
detects the current installation of Pester is signed with a different signature than the one you are installing.
Here's the command you need to run as administrator in order to get the latest version of Pester:
Install-Module -Name Pester -Force -SkipPublisherCheck
The -SkipPublisherCheck
option is typically required for machines that only have v3.4.0 installed as mentioned above.
That particular version of the module was signed by Microsoft to be shipped in-box, which is not the case for later versions which are community maintained and signed with a different certificate.
Attempting to install the module without that option may fail.
If you receive the following warning when trying to install the module, you may need to explicitly enable TLS 1.2:
WARNING: Source location 'https://www.powershellgallery.com/api/v2/packages/Pester/4.10.1' is not valid
To enable TLS 1.2 for the current PowerShell instance, you can run the following code, and then re-run the installation command:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocol]::Tls12
Removing the Built-In Version of Pester
If you need to remove the built-in version of Pester on your machine, you can do so by executing the following code:
$module = "C:\Program Files\WindowsPowerShell\Modules\Pester"
takeown /F $module /A /R
icacls $module /reset
icacls $module /grant "*S-1-5-32-544:F" /inheritance:d /T
Remove-Item -Path $module -Recurse -Force -Confirm:$false
Install-Module -Name Pester -Force
For any subsequent update it is enough to run:
Update-Module -Name Pester
Installing from PSGallery on other versions of Windows
The way you can install a new module differs based on the version of PowerShell you are using. Determine the version of PowerShell you are using by running:
$PSVersionTable.PSVersion
PowerShell 5 or newer
In version 5 or newer you can use the built-in Install-Module
and Update-Module
cmdlets coming from PowerShellGet.
From an administrative PowerShell command line run:
Install-Module -Name Pester
Or to update:
Update-Module -Name Pester
PowerShell 3 and 4
On PowerShell 3 and 4, there is no default package manager installed, but luckily PowerShellGet is available for installation. See detailed instructions here. When you have the package manager installed, please start a new administrator PowerShell window and use:
Install-Module -Name Pester
Or to update:
Update-Module -Name Pester
Installing manually
To install Pester you don't have to use any package manager. Downloading and installating it manually can be useful in e.g. offline envionments.
- Download the module on a machine with internet using either:
- Recommended:
Save-Module -Name Pester -Path C:\Temp
. It will save it in a versioned folder, ex C:\Temp\Pester\5.0.4 - Or download the NuGet package from PowerShell Gallery, see Manual Package Download
- Recommended:
- 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 it will by default include:
- C:\Users\User123\Documents\WindowsPowerShell\Modules
- C:\Program Files\WindowsPowerShell\Modules
- C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
- Start PowerShell and start testing.
note
Step 2 is optional if you don't need simple import, automatic module detection or module auto-loading. If so, you need to import the module using an absolute path like Import-Module C:\Temp\Pester\5.0.4
.
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 using NuGet. These options may not support pre-release versions and it may need to be initialized on first use. For those reasons you might prefer installing from the other available sources.
Chocolatey
Chocolatey (or choco) is the easiest way to get Pester running on AppVeyor. You avoid setting up PowerShellGet and it also supports pre-release versions.
choco install Pester
Or to update:
choco upgrade Pester
You can also pass the --prerelease
option to install or update to a prerelease version of Pester instead.
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. 🙂