I have been using Pester for some PowerShell tests. From the command prompt all is good, but I kept getting the error ‘module cannot be loaded because scripts is disabled on this system’ when I tried to run them via the Visual Studio Test Explorer

image

I found the solution on StackOverflow, I had forgotten that Visual Studio is 32bit, so you need to set the 32bit execution policy. Opening the default PowerShell command prompt and and setting the policy only effect the 64Bit instance.

  1. Open C:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe
  2. Run the command Set-ExecutionPolicy RemoteSigned
  3. My tests passed (without restarting Visual Studio)

image