PowerShell(2.0,32位)无法加载TFS 2010管理单元...除非可以

时间:2013-12-13 21:01:02

标签: powershell tfs

我有一个与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和提供程序   会话。

“你”可以,嗯? “你”是谁?是的,你可以。

但是怎么样?

1 个答案:

答案 0 :(得分:0)

我的问题几乎与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中,双击它,它应该在两个PowerShells中都可以使用该管理单元:

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"