Share via


Powershell Extensions for TFS

Question

Tuesday, December 11, 2018 7:10 PM

Hi All,

I recently upgraded from VS2012 to VS2017.  We used the VS2012 Powertools Powershell extensions for TFS (Microsoft.TeamFoundation.Powershell) to extract files from a range of change sets.  Powertools does not exist for VS2017.  I found a post that pointed me to this page: https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=vsts where I was able to download the Microsoft.TeamFoundationServer.ExtendedClient module.  I installed it into the C:\Windows\System32\WindowsPowerShell\v1.0\Modules directory, however when I try to add it as a snap in, I get an error message that it cannot be found.  What have I done wrong?

PS C> Add-PSSnapIn Microsoft.TeamFoundationServer.ExtendedClient
Add-PSSnapIn : The Windows PowerShell snap-in 'Microsoft.TeamFoundationServer.ExtendedClient' is not installed on this computer.
At line:1 char:1

  • Add-PSSnapIn Microsoft.TeamFoundationServer.ExtendedClient

    + CategoryInfo          : InvalidArgument: (Microsoft.TeamF....ExtendedClient:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

Thanks in advance for any help.

All replies (6)

Monday, December 17, 2018 7:41 PM ✅Answered

Hi May,

I have successfully replicated the functionality of the script we used with Powertools 2012 using the REST API.  The script below extracts the file names associated with a range of changesets in a given branch of TFS.  I am sure someone who is more experiened with PowerShell could make it more streamlined, but it provieds the information I needed.

Thank you for pointing me in the right direction.

Joe

param([string]$Branch = "Test", [string]$Schema = "XXX", [string]$StartCS, [string]$EndCS, [string]$Output)

#   Set up environment
  $tfsServerString = "http://<tfs server name>:8080/tfs/DefaultCollection"
  $ItemPath = "$/Agile/" + $Branch + "/Src/Oracle/" + $Schema

#   Get a list of the changesets
  $URL = $tfsServerString +"/_apis/tfvc/changesets?searchCriteria.fromId=" + $StartCS + "&searchCriteria.toId=" + $EndCS + "&searchCriteria.itemPath=" + $ItemPath
  $ChangeSets = Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials
  $Files1 = " "," "
  $Files = {$Files1}.Invoke()

#   Get file names associated with each changeset
  for ($i=0;$i -lt $ChangeSets.Count; $i++) {
      $CSDtl = ""
      $CSid = $ChangeSets.value[$i].changesetID
      $URL = $tfsServerString +"/_apis/tfvc/changesets/"+ $CSid +"/changes"
      $CSDtl = Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials

      for ($j=0;$j -lt $CSDtl.Count; $j++) {
          $Files.Add($CSDtl.value[$j].item.path)
      }
  }
  $X = $Files.Remove(" ")
  $Files = $Files | select -uniq | Sort-Object

#   Write the results
  Out-File -filepath $Output -inputObject $Files -encoding ASCII -width 150 -append

Wednesday, December 12, 2018 7:20 AM

Hi Joe S 63,

Welcome to the MSDN forum.

I found a similar thread that mentioned what you said about this extension and the reference link. After I checked that, found this Nuget package is aim to client api. But as far as I know, if you want to use it in VS 2017, you need to re-complier script and debug by yourself.

As we know, Powertools does not exist for VS2017. Could you tell me what’s feature of TFS Power Tools you used? If you used some features as blow I strongly recommend you to use vsts-clitfx-cli and vsteam. And the Windows Shell Extensions ship stand-alonein VS 2017.

  • Check-in policies
  • Storyboard Shapes
  • Team Explorer Enhancements
  • Windows PowerShell Cmdlets
  • Windows Shell Extensions

More info please check this link: https://marketplace.visualstudio.com/items?itemName=ms-vscs-vcw.TfsShellExtention and https://stackoverflow.com/questions/51292811/do-tfs-power-tools-have-any-use-in-a-vsts-only-scenario .

Hope my answer would help you much.

Best Regards

May

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected]


Wednesday, December 12, 2018 11:56 AM

Hi May.  Thanks for the information.  I'll take a look at the links you provided.  In the meantime, here is the script we use to extract the file names from a range of change sets.

param([string]$Branch = "Test", [string]$Schema = "Schema", [string]$StartCS, [string]$EndCS, [string]$Output)
if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}
$tfsServerString = "http://<server>:8080/tfs/DefaultCollection"
$tfs = Get-TfsServer -Name $tfsServerString
Get-TfsItemHistory "$/Agile/$Branch/Src/Oracle/$Schema" -Server $tfs -version "C$StartCS~C$EndCS" -r -IncludeItems|select-object -expand "Changes" |where-object { ($_.ChangeType -band ([Microsoft.TeamFoundation.VersionControl.Client.ChangeType]::Merge  -bor [Microsoft.TeamFoundation.VersionControl.Client.ChangeType]::Edit )) -gt 0 } | Select-TfsItem | Group-Object Path | Select-Object Name | Sort-Object Name | Format-Table -hideTableHeaders -Auto | Out-File $Output -encoding ASCII -width 150 -append


Thursday, December 13, 2018 5:56 AM

Hi Joe S 63,

About your requirement of script that to extract the file names from a range of change sets is feasible. You could refer to /en-us/previous-versions/visualstudio/visual-studio-2010/w51xa47k%28v%3dvs.100%29 and /en-us/rest/api/azure/devops/tfvc/changesets/get?view=azure-devops-rest-5.0 . then to complier your script.

May

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected]


Thursday, December 13, 2018 8:14 PM

Hi May,

I think using the REST API is probably my best bet, however, when I try to get the change set details (which I think contains the file names that were changed) I get a page not found error.  Also, I was trying to get a range of changesets, but I only get information back from the first one.  Our TFS backend is still 2012, Do you know if TFS 2012 supports REST API 5.0?

This works to get general information on a single changeset, but I was hoping to get a list of the changesets in the From/To range for the specified path.

#  Get a list of the changesets
  $ItemPath = "$/Agile/" + $Branch + "/Src/Oracle/" + $Schema
  $URL = $tfsServerString +"/_apis/tfvc/changesets/"+ $StartCS +"?searchCriteria.fromId=" + $StartCS + "&searchCriteria.toId=" + $EndCS + "&searchCriteria.itemPath=" + $ItemPath
  $ChangeSets = Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials
  echo $ChangeSets

This returns a page not found error message:

  $URL = $tfsServerString +"/_apis/tfvc/changesets/"+ $StartCS +"/changes?api-version=5.0-preview.1"
  $CSDtl = Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials

Any help will be greatly appreciated.


Friday, December 14, 2018 7:25 AM

Hi J Wadle,

TFS 2012 is too old to unable to support REST API. You’d better update to TFS 2015 or later.

May

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected]