Why does PowerShell cut off column values?

Viewed 44504

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

The info Syed provided does help (increasing the screen buffer width). However, if you use -AutoSize, the last column might still get truncated. To solve that issue, you would need to explicitly set the width you'd like for that column. It might not look pretty, but it works. For example:

#:: ft = Format-Table, n = name, e = expression, a = alignment
$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 3000
$pswindow.buffersize = $newsize
    
Get-AppxPackage | sort name | ft @{n='Name';e={$_.Name};a='left';width=44}, @{n='Version';e={$_.Version};a='left';width=20},@{n='InstallLocation';e={$_.InstallLocation};a='left';width=105} >D:\Installed_AppX_Packages.txt

In the above command, I'm outputting a list of installed AppX packages to a file. I've explicitly set each column to a certain width. Without doing so, the last column (InstallLocation) has some values cut-off. So I checked which value was the longest, and set the width accordingly.

Related