问题
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:
Just to connect the dots. "urig" answered his own question in another topic: TFS Power Tools 2008 Powershell Snapin won't run in on 64-bit in Windows 2008 R2
"Cathy Kong of Microsoft was kind enough to provide me with a workaround for this issue. The full details can be found here in the MSDN TFS PowerTools forum: http://social.msdn.microsoft.com/Forums/en-US/tfspowertools/thread/a116799a-0476-4c42-aa3e-45d8ba23739e/?prof=required
The fix is as follows and worked well for me:
Please save the following content and save it as *.reg file and import to Registry(just double click the *.reg file, click OK double)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell] "PowerShellVersion"="2.0" "Vendor"="Microsoft Corporation" "Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets." "VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft" "DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets." "Version"="10.0.0.0" "ApplicationBase"="C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools" "AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" "ModuleName"="C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\Microsoft.TeamFoundation.PowerTools.PowerShell.dll" "CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"
回答2:
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
回答3:
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
回答4:
For those finding this in the future, I'd like to add that you should double check how you launch powershell. I was getting the same error, and couldn't figure out why the solutions were all in reference to using the 64 bit version, when I thought I already was.
It turns out that because I was running powershell with a third party 32 bit launcher, powershell was falling back to the 32 bit executable, despite being launched from the system32 folder. Thanks to x0n for the method of confirming the version I was using, as this lead me to my solution.
回答5:
Opening powershell with the below command solved my issue :
%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe
Just invoke the powershell 64 bit version with the above command and pass the script path with arguments to it.
来源:https://stackoverflow.com/questions/3501001/windows-powershell-snap-in-for-iis-fails-on-32-bit