On-Prem Azure Pipelines Pester Tests Fail with ##[error]Unhandled: spawn pwsh ENOENT

I've been playing around with Azure DevOps Pipelines in my quest to become a better programmer. After spinning up an on-prem agent running on Server 2019, I kept getting the error for a subset of my Pester tests for some modules, all of which run fine in the cloud. The error isn't really helpful in determining what it's upset about other than that it can't spawn a PowerShell process.


tl;dr: remove the default Pester module, install the new version, reboot.

Originally, I thought it was because of some error in my PATH or that the version of PowerShell needed to be different. So after re-installing PowerShell, cleaning up my system and user PATH variables, installing a different version of PS Core, I realized that the only tests that failed were the ones that I'd either written, or converted to Pester 5.

Installing an updated version of Pester didn't help, and rather than altering my $env:PSModulePath to force the proper version of Pester to load, I figured nuking the old version was a better bet.

Since Pester is installed as a default system module, you can't just pluck it out, but the instructions from the Pester v5 docs will give you this:

$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

After you've replaced the version of Pester that ships with Windows, all your Pester 5 tests should run and the little blue spinner will turn green and your life will be better.

Maybe.

Show Comments
.post-template p { text-align: justify; }