I had the exact same problem because I was calling the wrong version of PowerShell from my program. I'm not sure about this but I think when you have a x86 program it calls the x86 version of PowerShell, which fails.
To specifically use the 32-bit version, call this one from your program:
C:WindowsSysWoW64WindowsPowerShellv1.0powershell.exe
To use the 64-bit version (on a 64-bit OS), call this one from your program:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
Using C:WindowsSysNativeWindowsPowerShellv1.0powershell.exe
from within a 32bit process will give you the 64bit powershell. Using it from within a 64bit process will give you a file-not-found error.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…