7

I only want to check out a path with powershell and also check in this path one minute later at Team Foundation Server.

How can i do this?

I have installed the tfs power tools at my server.

user1218240
  • 195
  • 1
  • 4
  • 13

5 Answers5

10

You don't need the power tools. Just use the tf.exe command line util that comes with Visual Studio with TFS Team Explorer. tf edit <file> /noprompt to check out and tf checkin <file> /comment:$comment /noprompt to check in. Look at the command line usage on tf.exe for more info tf /? and tf checkin /?. You will need to configure your PowerShell session with the Path to tf.exe. This is usually done by the VS vars batch files. But you should be able to simply add to the path like so: $PATH += "${VS110COMNTOOLS}..\Ide".

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
6

Here is a function which will check to see if the snapin is installed. If you installed the powertools, it uses that, otherwise, it uses the command line tool tf.exe

function checkout-file([string] $file)
{
    "Checking out $file"
    if ((Get-PSSnapin -Name  Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    {
        Add-PsSnapin  Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue

        if ((Get-PSSnapin -Name  Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
        {
            #try to check out the code using command line tf.exe
            &"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe" checkout $file | Out-Null
        }
        else{
            #checkout the file using snapin
            Add-TfsPendingChange -Edit $file | Out-Null
        }
    }else{
        #checkout the file using snapin
        Add-TfsPendingChange -Edit $file | Out-Null
    }
}
Jim
  • 1,088
  • 9
  • 12
  • 1
    This worked like a charm. I only had to change the visual studio version to match mine. Would be cool if it cycled through ${VS###COMNTOOLS} in descending order until it found one. – Benrobot Jul 22 '16 at 16:31
  • @Benrobot - I threw this together really quick, but you could try this. `$cmntools = Get-ChildItem -Path 'Env:\VS*COMNTOOLS' | Sort-Object -Property 'Name' -Descending | %{ ($_.Value.replace('\Tools\','\IDE\TF.exe') ) }` – Jim Aug 12 '16 at 19:47
3

This is my solution:

$tf = &"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe"     checkout C:\setup\folder /recursive
$tf | Out-null
user1218240
  • 195
  • 1
  • 4
  • 13
2

If you have the power tool commandlets installed for powershell. You don't need the Path like Kieth mentions, part of the commandlets aliases tf for the full tf.exe path. So, simply use the tf.exe command line reference here and all of these should work if you have the powershell commandlets installed correctly.

You should make sure your powershell has them installed by using this command though

 Add-PSSnapin Microsoft.TeamFoundation.PowerShell
Alex
  • 12,749
  • 3
  • 31
  • 45
  • Be aware that, last I checked, the TFPT cmdlets only worked in 32-bit PowerShell. The tf.exe approach works in both 32-bit and 64-bit PowerShell. :-) – Keith Hill Dec 04 '12 at 00:26
  • @KeithHill the most recent update (works with 2012 update 1) now has 64bit support - http://blogs.msdn.com/b/bharry/archive/2012/11/30/new-power-tools-for-update-1-are-available.aspx – Betty Dec 04 '12 at 08:23
  • Keith, I understand yoru points, and that is the way I would do it as well. But, the question is, how to do it with Powertools powershell. – Alex Dec 04 '12 at 15:11
  • @Betty, yeah I saw Brian Harry's post about it last night. That eliminates a big annoyance with those cmdlets. :-) – Keith Hill Dec 05 '12 at 04:13
  • 1
    @Alex, of course, if you're going to use TFPT then you might as well use the cmdlets `Add-TfsPendingChange` and `New-TfsChangeset`. :-) – Keith Hill Dec 05 '12 at 04:24
0

Another option is to use the wild-card if you're trying to handle multiple files in the same command without picking up other files or looping over them.

   tf.exe undo AssemblyInfo* /recursive
   tf.exe checkout AssemblyInfo* /recursive
   #changes files
   tf.exe checkin AssemblyInfo* /recursive