4

我正在尝试编写一个 PowerShell 脚本来自动化我的 IIS 网站部署。我正在尝试在我的 Windows Server 2008 R2 机器上运行脚本,在 32 位以下:

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

每当我运行这样的 WebAdministration 命令时:

Get-Website -Name "MYWebsite"

我收到这样的错误:

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

切换到 64 位版本的 PowerShell.exe 解决了这个问题,但我无法同时使用 Microsoft Team Foundation Server 2008 Power Tools PSSnapin,这对我来说是不行的。

知道如何克服这个问题吗?提前致谢。

4

5 回答 5

7

跑步:

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

实际上加载了32 位版本的 powershell ;-)

这显然不是你想要的。运行system32中的版本,得到64位版本。对真的。

您可以像这样验证:

ps> [intptr]::size
4

如果它返回 4,它是 32 位的。64 位 powershell 将返回 8。

-Oisin

于 2010-08-17T15:06:22.787 回答
3

您可能会尝试的一件事是按照 Oisin 的说法加载 64 位 PowerShell,然后使用 Start-Job -RunAs32 执行加载 TFS PowerTools 管理单元并根据需要执行 TFS cmdlet 的脚本。请务必从后台作业中运行的命令输出所需的信息。使用 Wait-Job 等待它完成,然后使用 Receive-Job 将数据从 32 位端获取回您的主 64 位 PowerShell 会话,例如

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
于 2010-08-17T22:39:59.123 回答
1

对于那些将来发现这个问题的人,我想补充一点,你应该仔细检查你是如何启动 powershell 的。我遇到了同样的错误,并且无法弄清楚为什么解决方案都参考了使用 64 位版本,而我认为我已经这样做了。

事实证明,因为我正在使用第三方 32 位启动器运行 powershell,所以尽管是从 system32 文件夹启动的,但 powershell 还是回退到了 32 位可执行文件。感谢 x0n 提供了确认我正在使用的版本的方法,因为这让我找到了我的解决方案。

于 2012-08-20T19:21:45.933 回答
1

使用以下命令打开 powershell 解决了我的问题:

%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe 

只需使用上述命令调用 powershell 64 位版本,并将带有参数的脚本路径传递给它。

于 2018-06-19T12:59:37.443 回答
0

只是为了连接点。“urig”在另一个主题中回答了他自己的问题: TFS Power Tools 2008 Powershell Snapin will not run in 64-bit in Windows 2008 R2

“Microsoft 的 Cathy Kong 非常友好地为我提供了解决此问题的方法。完整的详细信息可以在 MSDN TFS PowerTools 论坛中找到:http ://social.msdn.microsoft.com/Forums/en-US/ tfspowertools/thread/a116799a-0476-4c42-aa3e-45d8ba23739e/?prof=必需

修复如下,对我来说效果很好:

请将以下内容保存为*.reg文件并导入注册表(双击*.reg文件,双击确定)

Windows 注册表编辑器版本 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell] "PowerShellVersion"="2.0" "Vendor"="Microsoft Corporation" "Description"="这是一个包含团队的 PowerShell 管理单元Foundation Server cmdlet。” "VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft" "DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,这是一个包含 Team Foundation Server cmdlet 的 PowerShell 管理单元。" "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,文化=中性,

于 2010-12-11T02:26:19.433 回答