Get-TfStatus


Been far too long since I blogged about a new PowerShell script.  This is not to say I’ve stopped using PowerShell, more that I’ve been too busy playing with other tools to spend a significant amount of time updating my scripts.

This is a simple, yet straight forward script.  The intent is to make the “tf status” command easier to use from PowerShell.  I often want to do some last second verification on files I’ve altered.  The default output is not easy to one time parse so a script is handy.

function Get-TfStatus() {
    param ( [string]$path= “.” ,
            [switch]$recursive = $false )

    $args = “”
    if ( $recursive ) {
        $args = “/r”
    }
    $output = [string[]](& tf status $path $args)

    # First two lines are junk so skip past it
    for ( $i = 2; $i -lt $output.Length; $i++ ) {
        $name,$edit,$path = $output[$i].Split(” “, [StringSplitOptions]”RemoveEmptyEntries”)
        if ( $path -and (test-path $path) ) {
            new-tuple “FileName”,$name,”Change”,$edit,”FilePath”,$path
        }
    }
}

$PS> get-tfstatus -r

FileName                   Change                     FilePath
——–                   ——                     ——–
File1.cpp               edit                       E:\dd\sourcepath\src\v…
File2.cpp               edit                       E:\dd\sourcepath\src\v…
File3.h                  edit                       E:\dd\sourcepath\src\v…

Comments (4)

  1. Wes Haggard says:

    Why not use the TFS managed API’s, instead of parsing the output?

    Someone really needs to flush out a nice set of powershell cmdlets for TFS, maybe I will look into when I get some of that free time we all talk about 🙂

    However to the point of tf status, one of my pet projects right now is a tool I call "tfv" which is a standalone tool that will provide a way for you to view the workspace changes, shelvesets and changesets (similar to sdv). I’m primarily doing it to learn WPF and the TFS api’s but it is also a pretty useful tool.

  2. The main reason I avoided the managed API’s was time.  I needed to get a quick solution to my problem and right now I’m fairly familiar with the WIT OM but I little experience with the Source Code Control OM.  

    Parsing the output is quick, effective and requires no additional investigation in terms of APIs.

    In addiotion, adding new features to a script has less overhead than adding a feature to a fully compiled program.  Say if I wanted to add one more value to the tuple, Server Path, it would take VIM and a few minutes of work.  Updating a compiled program would take a bit longer, require VS (which I may or may not have on a machine), find the source, update it, recompile, redeploy the binary and get the results.  

  3. The Accentient Blog on Tagging Team System Work Items. Grant Holliday on Hands-Free TFS Installation…

Skip to main content