Format-Table in a powerful command that you can use to format your output. output can be a console or a file out. Format-Table working with object or a object collection.
For an example If you have a object collection from your code you can out put as a table.
Get-SPSite -Limit All | Format-Table –AutoSize
-AutoSize will be use to format columns with depending of screen size. But if you are working with long width tables you better use Out-String -Width 4000 with output pipe. (4000 is a character count in horizontal, You can mention any suitable value )
Ex:-
Get-SPSite -Limit All| Format-Table –AutoSize | Out-String -Width 4000
You can use Format-Table with a single object as well.
Ex:- With all columns
$objAverage = New-Object System.Object
$objAverage | Add-Member -type NoteProperty -name Col1 -value "saman"
$objAverage | Add-Member -type NoteProperty -Name Col2 -Value 23423
$objAverage | Format-Table –AutoSize
Ex:- With mentioned columns
$objAverage = New-Object System.Object
$objAverage | Add-Member -type NoteProperty -name Col1 -value "saman"
$objAverage | Add-Member -type NoteProperty -Name Col2 -Value 23423
$objAverage | Add-Member -type NoteProperty -Name Col3 -Value 123
$objAverage | Format-Table Col1,Col2 –AutoSize
You can also create object collection, add objects and format it as a table.
$table = @()
$objAverage = New-Object System.Object
$objAverage | Add-Member -type NoteProperty -name Col1 -value "aa"
$objAverage | Add-Member -type NoteProperty -Name Col2 -Value 111
$objAverage | Add-Member -type NoteProperty -Name Col3 -Value 222
$table += $objAverage
$objAverage = New-Object System.Object
$objAverage | Add-Member -type NoteProperty -name Col1 -value "bb"
$objAverage | Add-Member -type NoteProperty -Name Col2 -Value 333
$objAverage | Add-Member -type NoteProperty -Name Col3 -Value 444
$table += $objAverage
$table | Format-Table –AutoSize
Comments