2016-07-30 103 views
0

对于Team Services帐户,我无法运行TFS 2013 Power Tools随附的任何PowerShell cmdlet。有问题的命令包括Get-TfsItemHistoryGet-TfsChangeset。这些工作正常与TFS的非托管实例,但不是团队服务。 我可以使用tf.exetfpt.exe成功连接到团队服务。 我的脚本如下所示与抛出的异常一起显示。 这些命令是否可以与Team Services一起使用,如果有的话,我做错了什么? 谢谢。如何查询使用Microsoft.TeamFoundation.PowerTools.PowerShell的Visual Studio Team Services(VSO)cmdlet

#my Team Services credentials: 
$Username = "[email protected]" 
$tfsPath = "https://myname.visualstudio.com/" 
$passwordFile=".\ps-password.pwd" 

# read passsword from file 
# NOTE: password previously stored within file using command: 
# read-host -prompt Password -assecurestring | 
# convertfrom-securestring | 
# out-file ps-password.pwd -ErrorAction Stop 
if (!(test-path $passwordFile)) 
{ 
    throw [System.IO.FileNotFoundException] "$passwordFile" 
} 
$Password = Get-Content "$passwordFile" | ConvertTo-SecureString 

$creds = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $Username,$Password 

$tfsServer = New-Object System.Uri("$tfsPath") 

$tfsCollection = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($tfsServer,$creds) 
$tfsCollection.Authenticate() 

# $tfsCollection | show-object # NOTE: content of collection looks good when viewed 

# PROBLEM COMMANDS: 
Get-TfsChangeset -latest -server $tfsCollection 
Get-TfsItemHistory "$/" -Server $tfsCollection -Version "D2010-01-01~D2016-08-01" -Recurse -IncludeItem 

错误产生:

Get-TfsChangeset : The filename, directory name, or volume label syntax is incorrect. 
At ~\myScript.ps1:30 char:1 
+ Get-TfsChangeset -latest -server $tfsCollection 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [Get-TfsChangeset], IOException 
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.TeamFoundation.PowerTools.PowerShell.GetTfsChangesetCommand 
+0

我只是你的代码试图在我与VSTS/VSO账户的一面,但没”没有看到任何问题,变更集可以成功获得。您提供的错误发生在“Get-TfsChangeset”时,是否在$ tfsCollection.Authenticate()期间发生任何错误?我还添加了我之前使用的powershell脚本来获取变更集供您参考。 –

回答

0

加入我的PowerShell脚本,供大家参考:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell 

$tfsPath = "https://xxxxxx.visualstudio.com/" 

[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $tfs = get-tfsserver $tfsPath 

Get-TfsChangeset -latest -Server $tfs 
Get-TfsItemHistory "$/" -Server $tfs -Version "D2016-07-27~D2016-08-01" -Recurse -IncludeItem 
+0

我得到完全一样的行为。包含Add-PSSnapin语句不会改变我的特殊情况下的结果,因为我将它作为我的PowerShell配置文件的一部分加载(未在上面显示)。 – undertherope

+0

验证正常。有趣的是,如果绕过'Microsoft.TeamFoundation.Powershell'并使用'Microsoft.TeamFoundation.VersionControl.Client'程序集,我可以使用Powershell访问所需的数据。然而,这种方法涉及很多,我宁愿避免。 – undertherope