Is there a way to wordwrap results of a Powershell cmdlet?
I couldn't find something built in that allowed to to word-wrap to an arbitrary width, so I wrote one - a bit verbose but here it is:
function wrapText( $text, $width=80 )
{
$words = $text -split "\s+"
$col = 0
foreach ( $word in $words )
{
$col += $word.Length + 1
if ( $col -gt $width )
{
Write-Host ""
$col = $word.Length + 1
}
Write-Host -NoNewline "$word "
}
}
Format-Table has a -Wrap switch to wrap the last column. Since the last column of the output of Get-Member is pretty big already, this will produce readable results.
Another option is Format-Wide (but it doesn't wrap, so you are limited to console width):
Get-Process | Get-Member | Format-Wide Definition -Column 1
You can also try Format-Table -wrap
. For example:
(get-process -id 3104).startinfo.EnvironmentVariables | Format-Table -wrap
Output in table structures are auto-formatted to fit the width of the screen, truncating long values in the process if necessary.
Pipe the results into the format-list
command to get verbose, vertical formatting of the results.
PS> $object | get-member MethodWithLongSignature | format-list