1

I'm trying to automate some processes with Powershell. One of which, whenever we do branching, we have to manually udpate the "Current Release" query on our TFS site that searches User stories, so it has the right Release version in the search parameters. Example screenshots below.

enter image description here

This is where I would go on TFS to access the query and then edit it. Below is the editor screen, and I would replace the date fields in there with the date of the new release version. What I want is to access these fields via powershell (as some sort of TFS object, I would think) and update them.

enter image description here

I've been messing around with the TFS Power Tools for Powershell, as well as some of the object stuff when I get the server $server = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer($tfsURI). But through google-fu and just messing with it, I can't figure out how to edit the query from Powershell. Can anyone help?

user3066571
  • 1,381
  • 4
  • 14
  • 37

2 Answers2

0

This is not a direct answer to your question, but below is probably enough to get you started figuring it out for yourself. I think you will likely make use of $version_control_server

##
# http://blog.majcica.com/2015/11/15/powershell-tips-and-tricks-retrieving-tfs-collections-and-projects/
#   this will get you a list of tfs projects hosted on a tfs server
##

# Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-Type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll'

$uri = 'http://host:8080/tfs'

$tfsConfigurationServer = [Microsoft.TeamFoundation.Client.TfsConfigurationServerFactory]::GetConfigurationServer($uri)
$tpcService = $tfsConfigurationServer.GetService('Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')

$sortedCollections = $tpcService.GetCollections() | Sort-Object -Property Name

#

$collection = $sortedCollections[0]

$collectionUri = $uri + '/' + $collection.Name
$tfsTeamProject = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($collectionUri)
$cssService = $tfsTeamProject.GetService('Microsoft.TeamFoundation.Server.ICommonStructureService3')   
$sortedProjects = $cssService.ListProjects() | Sort-Object -Property Name


##
# https://lajak.wordpress.com/2013/01/28/tfs-2012-api-find-all-solutions-in-source-control/
#  this will take your list of projects and get list of solution paths within those projects
##


Add-Type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.VersionControl.Client.dll'

$version_control_server = $tfsTeamProject.GetService('Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer')

$solution_items = $version_control_server.getitems(
    '$/*',
    [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest,
    [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full,
    [Microsoft.TeamFoundation.VersionControl.Client.DeletedState]::NonDeleted,
    [Microsoft.TeamFoundation.VersionControl.Client.ItemType]::File
)

$path_array = $solution_items.items | foreach-object { $_.serveritem }

($path_array -join "`r`n") | out-file 'C:\tfs_paths.txt'

##
sam-6174
  • 3,104
  • 1
  • 33
  • 34
0

TFS Power Tools cannot achieve this feature. You'd either use the .Net Client Libraries like mentioned in this article or call VSTS Rest API to do this: Update a query.

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60