Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - formatting output column width

Reply
 
Old 02-23-2009   #1 (permalink)
Walt S


 
 

formatting output column width

I grabbed this code from someone's website to help learn PS.

Seems like it would be very handy--it recurses the home directory and lists
the size of subdirectories.

But the output colum for Path is truncated and displays ... so the script is
nearly worthless for telling me what the path is...

Any tips to get it to display the full name or change the width of the
column?

==============

Get-Childitem $home | Where-Object { $_.PSisContainer } |

ForEach-Object {

Write-Progress 'Examining Folder' ($_.FullName); $_ } |

ForEach-Object { $result = '' |

Select-Object Path, Count, Size;

$result.path = $_.FullName;

$temp = Get-Childitem $_.FullName -recurse -ea SilentlyContinue |

Measure-Object length -sum -ea SilentlyContinue ;

$result.count = $temp.Count;

$result.Size = $temp.Sum;

$result

}



My System SpecsSystem Spec
Old 02-23-2009   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: formatting output column width

Quote:

> }
>
>
Try adding at the end:
|Format-Table -AutoSize

So you have:
....
}|Format-Table -AutoSize

Marco
My System SpecsSystem Spec
Old 02-23-2009   #3 (permalink)
Walt S


 
 

Re: formatting output column width

Oh, thank you, I've now discovered the Format-* commands!

"Marco Shaw [MVP]" <marco.shaw@xxxxxx_SPAMgmail.com> wrote in message
news:eo4TG2elJHA.5016@xxxxxx
Quote:

>
Quote:

>> }
>>
>>
>
> Try adding at the end:
> |Format-Table -AutoSize
>
> So you have:
> ...
> }|Format-Table -AutoSize
>
> Marco

My System SpecsSystem Spec
Old 02-23-2009   #4 (permalink)
Josh Einstein


 
 

Re: formatting output column width

I've also created this small function which is really useful when you want
to set the size of the buffer. For example, I recently started using
PowerShell scripts in my Visual Studio post-build events and the output
would get truncated at 80 chars in the output window. All I had to do to fix
it was call my Set-WindowBuffer function to specify a width of 300 chars.

##############################################################################
#.SYNOPSIS
# Sets the width and/or height of the console's window buffer which can be
# used to set a large scrollback buffer so that information isn't lost.
#
#.PARAMETER Width
# The buffer width, in characters. If not set, the width is unchanged.
#
#.PARAMETER Height
# The buffer height, in characters. If not set, the height is unchanged.
#
#.EXAMPLE
# Set-WindowBuffer -Width 500
# Set-WindowBuffer -Width 500 -Height 5000
##############################################################################
function Set-WindowBuffer($Width, $Height) {

$ErrorActionPreference = 'SilentlyContinue'

trap { Write-Warning 'Could not set window buffer size.' }

$size = $Host.UI.RawUI.BufferSize

if ( $Width ) { $size.Width = $Width }
if ( $Height ) { $size.Height = $Height }

$Host.UI.RawUI.BufferSize = $size

}


Josh

"Walt S" <someone@xxxxxx> wrote in message
news:e1qNr7dlJHA.4696@xxxxxx
Quote:

> I grabbed this code from someone's website to help learn PS.
>
> Seems like it would be very handy--it recurses the home directory and
> lists the size of subdirectories.
>
> But the output colum for Path is truncated and displays ... so the script
> is nearly worthless for telling me what the path is...
>
> Any tips to get it to display the full name or change the width of the
> column?
>
> ==============
>
> Get-Childitem $home | Where-Object { $_.PSisContainer } |
>
> ForEach-Object {
>
> Write-Progress 'Examining Folder' ($_.FullName); $_ } |
>
> ForEach-Object { $result = '' |
>
> Select-Object Path, Count, Size;
>
> $result.path = $_.FullName;
>
> $temp = Get-Childitem $_.FullName -recurse -ea SilentlyContinue |
>
> Measure-Object length -sum -ea SilentlyContinue ;
>
> $result.count = $temp.Count;
>
> $result.Size = $temp.Sum;
>
> $result
>
> }
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Solved Column width General Discussion
fixed width column import PowerShell
Change width of Excel Column PowerShell
Details View Column Width Defaults (Registry ??) Vista General
Details View Column Width Defaults (Registry ??) Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46