PowerShell 和 TFS |术语“tfpt”未被识别为 cmdlet 的名称
Posted
技术标签:
【中文标题】PowerShell 和 TFS |术语“tfpt”未被识别为 cmdlet 的名称【英文标题】:PowerShell and TFS | The term 'tfpt' is not recognized as the name of a cmdlet 【发布时间】:2020-06-12 17:29:30 【问题描述】:在我的客户端(不是 TFS 服务器)Windows 10 pro 工作站上本地运行并出现错误。我错过了什么?
> 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
下面的代码示例
# 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
工具:PowerShell ISE、TFS Server 2012、Windows PowerShell 2.0 引擎,还安装了: C:\Program Files (x86)\Microsoft Team Foundation Server 2012 电动工具 C:\Program Files (x86)\Microsoft Team Foundation Server 2013 电动工具 C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools
> Get-Host | Select-Object Version >> Version
> -------
> 5.1.17763.1007
尝试运行命令:
powershell -Command get-pssnapin -Registered
结果:
名称:SqlServerCmdletSnapin100 PS版本:2.0 描述:这是一个 PowerShell 管理单元,包括各种 SQL Server cmdlet。
名称:SqlServerProviderSnapin100 PS版本:2.0 说明:SQL Server 提供程序
名称:TfsBPAPowerShellSnapIn PS版本:2.0 说明:这是一个包含 Team Foundation Server cmdlet 的 PowerShell 管理单元。
名称:WDeploySnapin3.0 PS版本:2.0 说明:这是一个 PowerShell 管理单元,其中包含用于管理 Microsoft Web 部署基础结构的 cmdlet。
【问题讨论】:
错误提示在环境中找不到 cmdlet,尝试此链接修复此问题click here 谢谢您,点击链接,并且能够运行 TF 命令,但问题仍然存在 - 无法运行查询和 TFPT 命令 这能回答你的问题吗? powershell tf command not recognized as the name of a cmlet 【参考方案1】:解决了!
显然 TFPT 查询引擎 2010 使用某种只能在
中找到的旧 exe 文件https://marketplace.visualstudio.com/items?itemName=MartinWoodward.TeamFoundationServerPowerToolsDecember2011
第 1 步: 在 ISE 中运行以下命令:
notepad $PROFILE
这将打开您的 PowerShell 配置文件脚本。如果该文件不存在,它会提示您创建它。
第 2 步:添加以下行(如果您使用不同版本的 VS,请确保文件确实存在!)
Set-Alias tfpt "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\tfpt.exe"
【讨论】:
您可以Accept it as an Answer,这对阅读此主题的其他社区成员会有所帮助。以上是关于PowerShell 和 TFS |术语“tfpt”未被识别为 cmdlet 的名称的主要内容,如果未能解决你的问题,请参考以下文章
TFS 构建通过 REST API 和 PowerShell 发布测试结果 TRX
TFS 构建和 Powershell:如何访问预定义的构建变量