32
[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

New-WebApplication -Name 'testApp' -Site 'Default Web Site' -PhysicalPath c:\test -ApplicationPool DefaultAppPool 

That is the contents of test.ps1. When I run .\test.ps1 I get the following error.

New-WebApplication : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for compon ent with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154. At C:\code\work\users\mchevett\test.ps1:6 char:19 + New-WebApplication <<<< -Name 'testApp' -Site 'Default Web Site' -PhysicalPath c:\test -ApplicationPool DefaultAppPo ol + CategoryInfo : InvalidArgument: (:) [New-WebApplication], ParameterBindingException + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.IIs.PowerShell.Provider.NewWebApplicationCommand

This error message is not helping me at all. Any ideas how to get a better error message? Thanks for reading!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
funGhoul
  • 527
  • 1
  • 5
  • 8

2 Answers2

55

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.

dan-gph
  • 16,301
  • 12
  • 61
  • 79
s0ndeb0k
  • 566
  • 5
  • 2
  • 1
    I ran the x86 and it solved my issue - C:\Windows\System32\WindowsPowerShell\v1.0\ – Nick Josevski Aug 22 '12 at 05:05
  • 3
    On x64 operating systems `System32` is not actually for 32 bit components, `SysWOW64` is. That `SysNative` path pointed in the answer would be available for 32-bit process on 64-bit system and would allow it to invoke 64-bit powershell. – Mike Jan 22 '13 at 19:39
  • I recommend you use "%SystemRoot%\SysWoW64\WindowsPowerShell\v1.0\powershell.exe" to run the 64bit version of PowerShell. – Tom Hall Mar 16 '13 at 13:00
  • 6
    Tom Hall - The SysWoW64 directory contains the 32-bit version of PowerShell. – Castrohenge Jun 11 '13 at 09:38
  • This was my problem as well but unfortunately I was using Jenkins running on 32 bit mode to launch my PowerShell commands. I needed to install the 64 bit Java Runtime Environment so that Jenkins would run in 64 bit mode, so that it would then choose the 64 bit version of Powershell to run. – mattferderer May 19 '16 at 19:26
3

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

screenshot of configuration page

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
Raj Patel
  • 31
  • 2
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](https://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](https://stackoverflow.com/help/deleted-answers) – Alessio Oct 10 '19 at 20:23
  • @Alessio They weren't linking to an external resource, but rather a screenshot they uploaded of a window relevant to their solution. This is a useful answer, imo. – Das_Geek Oct 10 '19 at 21:04
  • Thanks @Alessio but since I am new here StackOverflow is restricting me to upload pictures until I have accumulated 10 points or upvotes I think. My answers will improve with more and more use of this platform more. – Raj Patel Oct 11 '19 at 16:47