PowerShell(2.0,32 位)无法加载 TFS 2010 管理单元...除非可以 [英] PowerShell (2.0, 32-bit) can't load TFS 2010 snap-in... except when it can

查看:29
本文介绍了PowerShell(2.0,32 位)无法加载 TFS 2010 管理单元...除非可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a PowerShell script which interacts with Team Foundation Server. When I run it in the PowerShell console, it works perfectly. This is nice for testing it, but I want to run it by double-clicking on it, or on a batch file or something. I'd even settle for right-clicking on it and selecting "Run with PowerShell".

但是当我这样做时,我得到一个错误.使用 PowerShell 运行"关闭窗口太快,无法查看错误是什么.有人在设计那个的时候真的在想,也许鲍尔默参与了.我也可以在 cmd.exe 中运行它,如下所示:

But when I do that, I get an error. "Run with PowerShell" closes the window too fast to see what the error is. Somebody was really thinking when they designed that, maybe Ballmer was involved. I can also run it in cmd.exe, like so:

PowerShell -File dostufftocheckouts.ps1

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

When I do that, I get to see an error message, and I'm guessing it might be the same one:

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 的新实例并在其中运行脚本时,一切正常.

When I start a new instance of the interactive PowerShell shell and run the script in that, everything works perfectly.

更新

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

I get the same error with either of the following PowerShell executables (since I seem to recall the TFS snapin was 32-bit only):

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

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

In cmd.exe, the following command produces the following output:

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:

So, I've written a very minimal script, 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 doesn't give me an error. But adding the snap-in doesn't make any of the snap-in's cmdlets visible to the rest of the script.

据称,Add-PsSnapin 向当前会话:

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

The Add-PSSnapin cmdlet adds registered Windows PowerShell snap-ins to the current session. After the snap-ins are added, you can use the cmdlets and providers that the snap-ins support in the current session.

你"可以,嗯?你"是谁?是的,当然可以.

"You" can, eh? "You" who? Yeah, sure you can.

但是怎么样?

推荐答案

我的问题几乎与 是否没有适用于 x64 上的 PowerShell 的 TFS 管理单元?TFS Power Tools 2008 Powershell 管理单元不会在 64 上运行-bit 在 Windows 2008 R2 中,可能还有其他.

My question turns out to have been almost a duplicate of 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, and probably others.

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

I don't understand why different snap-ins were listed as "registered" the 32-bit PowerShell console vs running 32-bit powershell.exe (the WOW64 one is 32-bit) in cmd.exe, but whatever.

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

The answer appears to be here: The installer doesn't properly add the TFS snap-in to the Registry. The link shows you how to set it up to be usable from 64-bit PowerShell, but it appears that you need to do the same, at a different key, to make it usable from 32-bit PowerShell outside of the PowerShell console. So you paste the following into tfskludge.reg, double click it, and it should make the snap-in available in both 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"

这篇关于PowerShell(2.0,32 位)无法加载 TFS 2010 管理单元...除非可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆