【发布时间】: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 tfs powershell-2.0