Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PowerShell cut off column values?

Tags:

powershell

When I use autosize it only fixes the last column and then it breaks the first column, meaning all the values shows up for the last with a halfway chopped off value for the first column. Is there a fix for that?

Get-SPSite -WebApplication http://contoso.intranet.com -Limit All | where {$_.RootWeb.Created -ge $Yesterday -And $_.RootWeb.Created -lt $Tomorrow} | ft Url, @{Name='Created';Expression={$_.RootWeb.Created}},@{label="Size in MB";Expression={$_.usage.storage/1MB}} | Format-Table -Wrap -AutoSize
like image 991
Ninja Cowgirl Avatar asked Dec 06 '13 21:12

Ninja Cowgirl


People also ask

How do I get full output in PowerShell?

All you have to do is to go to Out-String and add the -Width parameter. Keep in mind that the -Width parameter of Out-File cmdlet specifies the number of characters in each line of output. Any other characters will simply be truncated, not wrapped.

How do I display output in a Table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.

Why do we need formatting in PowerShell?

You can use Format-List to format and display all or selected properties of an object as a list (Format-List -Property *). Because more space is available for each item in a list than in a table, PowerShell displays more properties of the object in the list, and the property values are less likely to be truncated.

What is FT in PowerShell?

Windows PowerShell Scripting – Format-Table (FT) Format-Table, or FT for short, controls the formatting of the output of your Windows PowerShell commands. Whenever presentation of information is important, pipe the script's output into Format-Table.


5 Answers

This gives the kind of output you would probably expect:

[command] | Format-Table -AutoSize | Out-String -Width 10000 #| clip.exe

For example, try this:

Get-ChildItem -Path "." | Select-Object * | Format-Table -AutoSize | Out-String -Width 10000 #| clip.exe

Format-Table -AutoSize fits to the expected output size, or the size of the elements, whichever is smaller. Since your output is probably less than 10,000 characters wide this command should fit to whatever your data is.

NOTE: clip.exe is a built in Windows command that lets you pipe onto the clipboard.

like image 130
Chris Rudd Avatar answered Oct 27 '22 02:10

Chris Rudd


Format-Table -Autosize is limited to the width of your screen buffer. One option would be to output it to a text file or use Out-GridView rather than Format-Table

e.g.

Get-SPSite -WebApplication http://contoso.intranet.com -Limit All 
| where {$_.RootWeb.Created -ge $Yesterday -And $_.RootWeb.Created -lt $Tomorrow} 
| ft Url, @{Name='Created';Expression={$_.RootWeb.Created}},@{label="Size in MB";Expression={$_.usage.storage/1MB}} 
| Format-Table -Wrap -AutoSize
| Out-String -Width 4096 `
| Out-File C:\SPSites.txt

or

Get-SPSite -WebApplication http://contoso.intranet.com -Limit All 
| where {$_.RootWeb.Created -ge $Yesterday -And $_.RootWeb.Created -lt $Tomorrow} 
| ft Url, @{Name='Created';Expression={$_.RootWeb.Created}},@{label="Size in MB";Expression={$_.usage.storage/1MB}} 
| Out-GridView  
like image 45
RobertKenny Avatar answered Oct 27 '22 04:10

RobertKenny


$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 3000
$pswindow.buffersize = $newsize

Add this to the top of your script, fixes length issues :) its a total hack but works :)

like image 45
Syed Avatar answered Oct 27 '22 04:10

Syed


You are passing the output of format-table to another format-table which may be causing the problems. Try replacing the first with a select-object, the command should look exactly the same otherwise:

select-object Url, @{Name='Created';Expression={$_.RootWeb.Created}},@{label="Size in MB";Expression={$_.usage.storage/1MB}}
like image 44
zdan Avatar answered Oct 27 '22 02:10

zdan


Get rid of -AutoSize. It's defeating the purpose of -Wrap. I also agree with zdan and Keith Hill that there's no reason to pipe one Format-Table into another and that you should just add the switches to the first instance.

So, try this:

Get-SPSite -WebApplication http://contoso.intranet.com -Limit All | ?{$_.RootWeb.Created -ge $Yesterday -And $_.RootWeb.Created -lt $Tomorrow} | ft -Wrap Url, @{n='Created';e={$_.RootWeb.Created}},@{n="Size in MB";e={$_.usage.storage/1MB}}  

(I abbreviated some things to reduce the scrolling. Also, AFAIK "Name" and "Label" are interchangeable in ft format specs; just pointing that out because I noticed that you used one of each.)

like image 41
Adi Inbar Avatar answered Oct 27 '22 02:10

Adi Inbar