Check-Out files from TFS 2010 with powershell

2019-04-26 15:14发布

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.

5条回答
爷的心禁止访问
2楼-- · 2019-04-26 15:43

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
    }
}
查看更多
我命由我不由天
3楼-- · 2019-04-26 15:48

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
查看更多
【Aperson】
4楼-- · 2019-04-26 15:48

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
查看更多
做自己的国王
5楼-- · 2019-04-26 15:51

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
查看更多
欢心
6楼-- · 2019-04-26 16:09

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".

查看更多
登录 后发表回答