2011-11-22 94 views
1

我將批處理文件轉換爲PowerShell,查詢TFS位置以返回最新的變更集並將其顯示在日誌文件中。這是該文件的編輯版本:從PowerShell擴展TF.exe結果的輸出

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

然而,從文本GET TF.EXE返回被切斷:

=========================== 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

模式CON的cols = 250做我的PowerShell控制檯.. –

+1

同樣的事情,我不能把那行,我不得不做一些額外的,但那是答案。 $ originalBufferSize = $ Host.UI.RawUI.BufferSize $ newBufferSize =新物體System.Management.Automation.Host.Size 250,$ originalBufferSize.Height $ Host.UI.RawUI.BufferSize = $ newBufferSize #TF .EXE這裏的東西 $ Host.UI.RawUI.BufferSize = $ originalBufferSize – dprice

+1

您是否嘗試過** BufferSize **屬性? –

回答

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