views:

98

answers:

2

I'm trying to write a PowerShell script that will automate my IIS website deployments. I'm trying to run the scripts on my Windows Server 2008 R2 machine, under 32-bit in:

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

Whenever I run a WebAdministration command such as this:

Get-Website -Name "MYWebsite"

I get an error like this:

Get-Website : Retrieving the COM class factory for component with CLSID {688EEE
E5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154.
At line:1 char:12
+ Get-Website <<<<  -Name "MyWebsite"
    + CategoryInfo          : NotSpecified: (:) [Get-Website], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Micr
   osoft.IIs.PowerShell.Provider.GetWebsiteCommand

Switching to the 64-bit version of PowerShell.exe resolves this issue but makes it impossible for me to also use the Microsoft Team Foundation Server 2008 Power Tools PSSnapin, which is a no-go for me.

Any idea how I can overcome this? Thanks in advance.

+1  A: 

Running:

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

actually loads the 32 bit version of powershell ;-)

This obviously not what you want. Run the version in system32 to get the 64bit version. Yes, really.

You can verify this like:

ps> [intptr]::size
4

If it returns 4, it's 32 bit. 64 bit powershell will return 8.

-Oisin

x0n
I think the problem he's running into is that he wants to use the TFS Snapin (32-bit only) in conjunction with the WebAdmin module which *appears* to be 64-bit only.
Keith Hill
+1  A: 

One thing you might try is to load up a 64-bit PowerShell as Oisin says and then use Start-Job -RunAs32 to execute script that loads the TFS PowerTools snapin and executes the TFS cmdlets as necessary. Be sure to output an required info from the commands that run in the background job. Use Wait-Job to wait for it to complete then use Receive-Job to get the data from the 32-bit side back into your main 64-bit PowerShell session e.g.

PS> [IntPtr]::Size
8
PS> $job = Start-Job { [intptr]::size } -RunAs32
PS> Wait-Job $job

Id              Name      State      HasMoreData     Location     Command
--              ----      -----      -----------     --------     -------
3               Job3      Completed  True            localhost    [intptr]::size


PS> Receive-Job $job
4
Keith Hill
Thanks again for setting me straight Keith. I've edited my question to reflect your correction. I'm still at a loss as to how I can get both the IIS PSProvider and the TFS Power Tools PSSnapin to work together. Any ideas?
urig
I know of no way to load a 32-bit snapin in the *same* PowerShell session as a 64-bit snapin. With the exception of using a 32-bit background job as explained in my answer.
Keith Hill