Nat
Nat

Reputation: 670

PowerShell and TFS | The term 'tfpt' is not recognized as the name of a cmdlet

Running locally on my client (not TFS server) Windows 10 pro workstation and getting the error. What am I missing?

> tfpt : The term 'tfpt' 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:\DeploymentManagement\Tests\GetBranchInfo.ps1:18
> char:21
> + $WorkItemResults =  tfpt query /format:tsv /collection:$TfsServer /wi ...
> +                     ~~~~
>     + CategoryInfo          : ObjectNotFound: (tfpt:String) [], CommandNotFoundException
>     + FullyQualifiedErrorId : CommandNotFoundException   The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:19 char:20
> + $WorkItemResults = $WorkItemResults -replace  "(.*)Query results:.*", ...
> +                    ~~~~~~~~~~~~~~~~
>     + CategoryInfo          : InvalidOperation: (WorkItemResults:String) [], RuntimeException
>     + FullyQualifiedErrorId : VariableIsUndefined   The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:21 char:20
> + $WorkItemResults = $WorkItemResults.Split("`t")
> +                    ~~~~~~~~~~~~~~~~
>     + CategoryInfo          : InvalidOperation: (WorkItemResults:String) [], RuntimeException
>     + FullyQualifiedErrorId : VariableIsUndefined   The variable '$WorkItemResults' cannot be retrieved because it has not been set. At
> C:\DeploymentManagement\Tests\GetBranchInfo.ps1:24 char:17
> + foreach($row in $WorkItemResults)
> +                 ~~~~~~~~~~~~~~~~
>     + CategoryInfo          : InvalidOperation: (WorkItemResults:String) [], RuntimeException
>     + FullyQualifiedErrorId : VariableIsUndefined

Code sample below

# Enforce coding rules
Set-StrictMode -version 2.0

# Loads Windows PowerShell snap-in if not already loaded
 if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
 {
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue
 }

$PbiParm = 89306  

# Get Iteration Path and PBI Title
$query = "SELECT [System.IterationPath], [System.Title] " + 
            "FROM WorkItems WHERE [System.Id] = " + $PbiParm

$TfsServer = "http://***tfs01:8080/tfs/Project"

$WorkItemResults =  tfpt query /format:tsv /collection:$TfsServer /wiql:$query
$WorkItemResults = $WorkItemResults -replace  "(.*)Query results:.*", ""

$WorkItemResults = $WorkItemResults.Split("`t")

$Index = 0
foreach($row in $WorkItemResults)
{
    $Index++

    Write-Host $Index

    if ($Index -eq 1 -or $Index -eq 2)
    {
        continue
    }

    if ($Index -eq 3)
    {
        $SprintName = $row
    }

    if ($Index -eq 4)
    {
        $PbiTitle = $row
    }

    if ($Index -eq 5)
    {
        break
    }
}

Tools: PowerShell ISE, TFS Server 2012, Windows PowerShell 2.0 Engine, and also installed: C:\Program Files (x86)\Microsoft Team Foundation Server 2012 Power Tools C:\Program Files (x86)\Microsoft Team Foundation Server 2013 Power Tools C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools

> Get-Host | Select-Object Version >>  Version       
> -------       
> 5.1.17763.1007

Tried to run the command :

powershell -Command get-pssnapin -Registered

RESULT:

Name : SqlServerCmdletSnapin100 PSVersion : 2.0 Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.

Name : SqlServerProviderSnapin100 PSVersion : 2.0 Description : SQL Server Provider

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

Name : WDeploySnapin3.0 PSVersion : 2.0 Description : This is a PowerShell snap-in that contains cmdlets for managing Microsoft Web Deployment infrastructure.

Upvotes: 0

Views: 1008

Answers (1)

Nat
Nat

Reputation: 670

SOLVED!

Apparently TFPT Query engine 2010 uses some sort of old exe file that could only be found in

https://marketplace.visualstudio.com/items?itemName=MartinWoodward.TeamFoundationServerPowerToolsDecember2011

Step 1: run in ISE the following:

notepad $PROFILE

This will open your PowerShell profile script. If the file doesn’t exist, it will prompt you to create it.

Step 2: Add following lines (amke sure files do exist first if you using different version of VS!)

Set-Alias tfpt "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\tfpt.exe"

Upvotes: 2

Related Questions