从PowerShell扩展TF.exe结果的输出

时间:2011-11-22 14:49:47

标签: powershell tfs

我将批处理文件转换为PowerShell,查询TFS位置以返回最新的变更集并将其显示在日志文件中。这是该文件的编辑版本:

function Get-TfsChangeset([string]$TfsPath, [int]$PreviousDays = 1)
{
    $TfExePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe"
    Write-Output "Getting history for '$TfsPath'..."
    Push-Location $LocalPath
    $Today = Get-Date
    $Prior = $Today.AddDays(-$PreviousDays)
    & "$TfExePath" history /recursive /format:brief /noprompt /version:D$($Prior.Month)/$($Prior.Day)/$($Prior.Year)~D$($Today.Month)/$($Today.Day)/$($Today.Year) $TfsPath
    Pop-Location
    Write-Output "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Done ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`n"
}

$ReportLogPath = "C:\temp\TfsHistoryReport.log"

Get-TfsChangeset "$/Some/Branch" > $ReportLogPath

Write-Output "Opening log '$ReportLogPath'..."
Start-Process notepad $ReportLogPath

然而,从TF.EXE GET返回的文本被截断:

=========================== Started: 11/22/2011 09:43:31 =========================

Getting history for '$/Some/Branch'...
Changeset User          Date       Comment
--------- ------------- ---------- --------------------------------------------
12345     ...adis       11/21/2011 Invalid code in the tags.  Need to fix this
12346     joe.blow      11/21/2011 Bug#1: Nothing is working so fix it right n
12347     john.smith    11/21/2011 Bug#2: I don't like the new UI changes so f
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Done ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=========================== Completed: 11/22/2011 09:43:42 =======================

通过将控制台列设置为如下所示,我能够在批处理文件中解决它:

mode con cols=250

但我不确定如何在PowerShell中这样做。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

来自OP的评论:

我无法放入mode con cols=250,我不得不多做一点,但这就是答案。

$oldBufferSize = $Host.UI.RawUI.BufferSize
$newBufferSize = New-Object Management.Automation.Host.Size 250,$oldBufferSize.Height
$Host.UI.RawUI.BufferSize = $newBufferSize
# TF.EXE stuff here
$Host.UI.RawUI.BufferSize = $oldBufferSize

另请参阅:Powershell output column width