PowerShell (2.0, 32-bit) cannot load the TFS 2010 snap-in ... unless it can

I have a PowerShell script that interacts with Team Foundation Server. When I run it in PowerShell, it works fine. This is good for testing, but I want to run it by double-clicking on it, either in a batch file or something like that. I even agreed to right-click on it and select "Run with PowerShell".

But when I do this, I get an error message. "Run using PowerShell" closes the window too quickly to find out what the error is. Someone really thought when they developed it, maybe Ballmer was involved. I can also run it in cmd.exe, for example:

PowerShell -File dostufftocheckouts.ps1

When I do this, I see an error message, and I assume that it can be the same:

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

The following code is included in the script before anything else:

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

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

UPDATE

I get the same error with any of the following PowerShell executables (since it seems like I remember that the snapin TFS was only 32-bit):

C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
C:\windows\System32\WindowsPowerShell\v1.0\powershell.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.

So, I wrote a very minimal script, joke.ps1:

Add-PsSnapin TfsBPAPowerShellSnapIn

$server = Get-TfsServer tfsserver/DefaultCollection

And I run it:

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 does not give me an error. But adding a snap does not make any of the binding cmdlets visible to the rest of the script.

Presumably, the Add-PsSnapin cmdlet adds snap to the current session:

Add-PSSnapin Windows PowerShell . , .

"" , ? " ? , .

?

0
1

TFS Snapin PowerShell x64?, TFS Power Tools 2008 Powershell Snapin 64- Windows 2008 R2 , , .

, "" 32- PowerShell 32- powershell.exe(WOW64 - 32-) cmd.exe, .

: TFS . , 64- PowerShell, , , , 32- PowerShell 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"
0

Source: https://habr.com/ru/post/1627966/


All Articles