Executing Powershell from CruiseControl.NET on 64-bit Windows

If you try to execute a Powershell script from a CruiseControl.NET build on a 64-bit OS, you’ll get the following error:

File ~filename~.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.

If you google around, you’ll be told to execute Set-ExecutionPolicy. Unfortunately, on 64-bit, that won’t fix your problem.

The issue is that CruiseControl.NET is 32-bit and the default powershell on 64-bit Windows is 64-bit. When a 32-bit process accesses SOFTWARE registry keys, the request gets redirected to HKLM\Software\Wow6432Node. This results in powershell looking for the wrong key and thus getting the default value.

To work around the problem, execute the following at an elevated command prompt:

%windir%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe “Set-ExecutionPolicy RemoteSigned”

In finding this solution it prompted me to realise that, in 64-bit Windows, c:\windows\system32 is 64-bit and c:\windows\SysWOW64 is 32-bit. And then my head exploded.