【问题标题】:PowerShell (2.0, 32-bit) can't load TFS 2010 snap-in... except when it canPowerShell(2.0、32 位)无法加载 TFS 2010 管理单元...除非它可以
【发布时间】:2013-12-13 21:01:01
【问题描述】:

我有一个与 Team Foundation Server 交互的 PowerShell 脚本。当我在 PowerShell 控制台中运行它时,它运行良好。这很适合测试它,但我想通过双击它或批处理文件或其他东西来运行它。我什至会满足于右键单击它并选择“使用 PowerShell 运行”。

但是当我这样做时,我得到一个错误。 “使用 PowerShell 运行”关闭窗口太快,无法查看错误所在。当他们设计那个时,有人真的在想,也许鲍尔默参与其中。我也可以在cmd.exe中运行,像这样:

PowerShell -File dostufftocheckouts.ps1

当我这样做时,我会看到一条错误消息,我猜它可能是同一个:

Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern 
'Microsoft.TeamFoundation.PowerShell' were found. Check the pattern and then 
try the command again.

以下代码首先包含在脚本中:

if ((Get-PSSnapin -Name  Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin  Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue
}

当我启动交互式 PowerShell shell 的新实例并在其中运行脚本时,一切正常。

更新

我在使用以下任一 PowerShell 可执行文件时遇到了相同的错误(因为我记得 TFS 管理单元只是 32 位的):

C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe

在 cmd.exe 中,以下命令产生以下输出:

c:\ powershell -Command "get-pssnapin -registered | where { $_.Name -eq 'TfsBPAPowerShellSnapIn' }"

Name        : TfsBPAPowerShellSnapIn
PSVersion   : 2.0
Description : This is a PowerShell snap-in that includes Team Foundation Server cmdlets.

所以,我写了一个非常简单的脚本,joke.ps1:

Add-PsSnapin TfsBPAPowerShellSnapIn

$server = Get-TfsServer tfsserver/DefaultCollection

然后我运行它:

c:\ powershell -File .\joke.ps1

The term 'Get-TfsServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\jmcnamara\PowerShell\broken.ps1:3 char:24
+ $server = Get-TfsServer <<<<  gearys/DefaultCollection
    + CategoryInfo          : ObjectNotFound: (Get-TfsServer:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Add-PsSnapin 不会给我一个错误。但添加管理单元不会使任何管理单元的 cmdlet 对脚本的其余部分可见。

据称,Add-PsSnapin 在当前会话中添加了一个管理单元:

Add-PSSnapin cmdlet 将已注册的 Windows PowerShell 管理单元添加到 当前会话。添加管理单元后,您可以使用 管理单元当前支持的 cmdlet 和提供程序 会话。

“你”可以,是吗? “你”是谁?是的,当然可以。

但是怎么做呢?

【问题讨论】:

标签: powershell tfs


【解决方案1】:

事实证明,我的问题几乎与 Is there no TFS Snapin for PowerShell on x64?TFS Power Tools 2008 Powershell Snapin won't run in on 64-bit in Windows 2008 R2 和可能其他问题重复。

我不明白为什么不同的管理单元被列为“注册”32 位 PowerShell 控制台与在 cmd.exe 中运行 32 位 powershell.exe(WOW64 是 32 位),但无论如何。

答案appears to be here:安装程序没有正确地将 TFS 管理单元添加到注册表中。该链接向您展示了如何将其设置为可在 64 位 PowerShell 中使用,但您似乎需要以不同的密钥执行相同操作,以使其可在 PowerShell 控制台之外的 32 位 PowerShell 中使用。因此,您将以下内容粘贴到 tfskludge.reg,双击它,它应该使管理单元在两个 PowerShell 中都可用:

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"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多