Created
August 7, 2012 19:06
-
-
Save nnieslan/3288447 to your computer and use it in GitHub Desktop.
Powershell function(s) to use TFS API services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Tfs | |
{ | |
param( | |
[parameter(Mandatory=$true, | |
Position=0, | |
HelpMessage="The TFS Server Url containing the Team Project Collection.")] | |
[alias("TFS")] | |
[string] $serverName, | |
[parameter(Mandatory=$false, | |
Position=1, | |
HelpMessage="A switch used to silence console output.")] | |
[switch] $silent | |
) | |
# load the required dll | |
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") | |
$propertiesToAdd = ( | |
('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'), | |
('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'), | |
('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'), | |
('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService'), | |
('TST', 'Microsoft.TeamFoundation.TestManagement.Client', 'Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService'), | |
('LAB', 'Microsoft.TeamFoundation.Lab.Client', 'Microsoft.TeamFoundation.Lab.Client.LabService'), | |
('LFS', 'Microsoft.TeamFoundation.Lab.Client', 'Microsoft.TeamFoundation.Lab.Client.LabFrameworkService'), | |
('LAS', 'Microsoft.TeamFoundation.Lab.Client', 'Microsoft.TeamFoundation.Lab.Client.LabAdminService') | |
) | |
if(-not $silent) | |
{ | |
write-host "Connecting to TFS Server $serverName..." | |
} | |
# fetch the TFS instance, but add some useful properties to make life easier | |
# Make sure to "promote" it to a psobject now to make later modification easier | |
[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName) | |
foreach ($entry in $propertiesToAdd) { | |
$scriptBlock = ' | |
[System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null | |
$this.GetService([{1}]) | |
' -f $entry[1],$entry[2] | |
$tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock) | |
} | |
return $tfs | |
} | |
function Get-ActiveBugs | |
{ | |
param( | |
[parameter(Mandatory=$true, Position=0, HelpMessage="The URL of the Team Project Collection")] | |
[alias("TFS")] | |
[string] $tfsUrl, | |
[parameter(Mandatory=$true, Position=1, HelpMessage="The Name of the Team Project")] | |
[alias("TP")] | |
[string] $projectName | |
) | |
$tfs = get-tfs $tfsUrl -silent | |
$project = $tfs.wit.Projects | ?{ $_.Name -eq $projectName} | |
#TODO - consider replacing with text for query or a file read -- StoredQueries is deprecated in newer versions of TFS API | |
$query = $project.StoredQueries | ?{ $_.Name -eq 'Active Bugs' } | |
$queryText = $query.QueryText.Replace("@project","'$projectName'") | |
$results = $tfs.wit.Query($queryText) | |
$results | foreach{ | |
#write out some info to the console for debugging/logging | |
Write-Host "========" | |
write-host $_.Id | |
Write-Host $_.Uri | |
Write-Host $_.Title | |
Write-Host $_.CreatedBy | |
Write-Host "========" | |
} | |
return $results | |
} |
How get files from a changeset ?
Alternative TFS PowerTools http://blogs.technet.com/b/heyscriptingguy/archive/2012/12/28/protect-your-powershell-scripts-with-version-control.aspx
I prefer Microsoft.TeamFoundation.Client if I can.
a complete and detailled stand aleone powershell kit can be found on "tfsKit" hosted here : https://github.com/freakydinde/Powershell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to do reverse, where i want to push result into TFS testResult. I have JAvaScript results as xml file which are generate by using grunt, want to push/publish those results into TestResult on TFS Build Server.
Any Ideas how can i do that ?