问题
I am trying to output to a text file the results of the powershell cmdlet Compare-Object
The problem is I cannot eliminate the ellipse truncation.
The code below provides a table formatting definition variable which specifies a width of 1000 for the Path column. Yet the output file always truncates the Path column at 122 characters.
The Compare-Object
cmdlet is comparing two ArrayLists which are just lists of file path strings from common folder paths between two servers.
What I am attempting to do is put the SideIndicator as the first column and the full path in the second. I do not want truncating of the file path.
$tableFormat = @{Expression={$_.SideIndicator};Label="Side Indicator";width=15}, @{Expression={$_.InputObject};Label="Path";width=1000}
$outputFilename = ($server1 + "_" + $server2 + "_FileCompare" + ".txt");
Compare-Object $Hive1FileArray $Hive2FileArray -IncludeEqual | Format-Table $tableFormat | Out-String | Out-File $outputFilename
I also tried removing Out-String
from the pipe makes no difference.
What is going wrong here?
Thanks
回答1:
Compare-Object $Hive1FileArray $Hive2FileArray -IncludeEqual |`
Format-Table $tableFormat -AutoSize |`
Out-String -Width 1000 |`
Out-File $outputFilename
Read
Get-Help 'Format-Table' -ShowWindow
or its Online Version:
-AutoSize
Adjusts the column size and number of columns based on the width of the data. By default, the column size and number are determined by the view.
Get-Help 'Out-String' -ShowWindow
or its Online Version:
-Width <Int32>
Specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped. If you omit this parameter, the width is determined by the characteristics of the host program. The default value for the Windows PowerShell console is 80 (characters).
Not much more to say not knowing Compare-Object
cmdlet input objects…
回答2:
I know this is a year old but another useful parameter of Format-Table is -wrap.
-Wrap [] Indicates that the cmdlet displays text that exceeds the column width on the next line. By default, text that exceeds the column width is truncated.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
来源:https://stackoverflow.com/questions/36505570/remove-ellipse-from-table-output