Powershell New-WebApplication

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:\Windows\SysWoW64\WindowsPowerShell\v1.0\powershell.exe

To use the 64-bit version (on a 64-bit OS), call this one from your program:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Using C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.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.


Changing Platform target to "x64" in project solution build properties worked for me:

screenshot of configuration page