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
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.
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.
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.
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.
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.
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
$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 :)
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}}
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With