Team Foundation PowerShell PSSnapin in October Team Foundation Power Tools Drop

Oh thank you, thank you TFS team!!!  This is a great development because it enables version control queries for mere mortals (ie those of us not well versed in SQL Reporting Services).  It also enables easily scriptable queries.  With the October Team Foundation Power Tools drop, you get a PowerShell console icon in the start menu or you can just add the following to your profile:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell

Once you’ve done that, here are the new cmdlets you get:

  • Add-TfsPendingChange
  • ConvertTo-FixedByte
  • ConvertTo-FixedPath
  • Get-TfsChangeset
  • Get-TfsChildItem
  • Get-TfsItemHistory
  • Get-TfsItemProperty
  • Get-TfsPendingChange
  • Get-TfsServer
  • Get-TfsShelveset
  • Get-TfsWorkspace
  • New-TfsChangeset
  • New-TfsShelveset
  • Remove-TfsPendingChange
  • Remove-TfsShelveset
  • Restore-TfsShelveset
  • Select-TfsItem
  • Set-TfsChangeset
  • Update-TfsWorkspace

Now that you have the Team Foundation snapin loaded, you can start doing some interesting stuff like finding out who has pending changes older than 30 days:

PS> Get-TfsPendingChange . -User * -Recurse | 
    where {$_.CreationDate -lt (get-date).AddDays(-30)} | 
    select OwnerName -expand PendingChanges | 
    format-table Filename, ChangeType, OwnerName, 
                 @{l="Server Folder";e={$_.ServerItem}} -auto

Or say you want to see the level of checkin activity over the past 30 days:

PS> $history = Get-TfsItemHistory . -Recurse -Stopafter 1000 | 
    Where {$_.CreationDate -gt (get-date).AddDays(-30)} | 
    Sort CreationDate | 
    Select Owner,
           @{n='CreationDate';e={$_.CreationDate.ToShortDateString()}}
PS> $history | Group CreationDate -noelem

Count Name                     
----- ----                     
    4 10/12/2008               
    7 10/13/2008               
  103 10/14/2008                
   67 10/15/2008                
   23 10/16/2008                
   13 10/17/2008                
    3 10/19/2008                
    3 10/20/2008                
   23 10/21/2008                
   19 10/22/2008                
   31 10/23/2008                
   67 10/24/2008                
   10 10/27/2008                
   13 10/28/2008                
   29 10/29/2008                
    7 10/30/2008                
    4 10/31/2008                
    3 11/3/2008                 
    2 11/4/2008                 
    7 11/5/2008                 
   10 11/6/2008                 
    3 11/7/2008

If you have the excellent PowerGadgets, then you could do this:

PS> $history | group CreationDate | 
    Out-Chart -Caption "Checkins/Day" -Size 480,320 -modal

And get this nice graph:

Now if I’m a project manager on a large team, I might want to see “who” is checking in a bunch of code right before a deadline.  That is easy enough:

PS> $history | Group CreationDate | 
    Foreach { "$($_.Name) - Total Checkins: $($_.Count)";
              $_.Group | group Owner | 
                  sort @{e={$_.Count};asc=$false},Name | 
                  Format-Table Count,Name -auto }

10/12/2008 - Total Checkins: 4

Count Name
----- ----
    4 Acme\moe

10/13/2008 - Total Checkins: 7

Count Name
----- ----
    3 Acme\moe
    2 Acme\socrates
    1 Acme\curly
    1 Acme\optimus

Querying is an especially powerful aspect of PowerShell and teamed with these new Team Foundation version control cmdlets, you have access to some interesting information.

psmdtag:snapin: Team Foundation Power Tools
psmdtag:snapin: TFPT

This entry was posted in PowerShell. Bookmark the permalink.

2 Responses to Team Foundation PowerShell PSSnapin in October Team Foundation Power Tools Drop

  1. kiquenet says:

    source code not visible, I can see it, only if I can select it .

    • rkeithhill says:

      Sorry folks. This blog was migrated automatically by a tool from Windows Live Spaces to WordPress and unfortunately the tool butchered the styling of my code snippets.

Leave a comment