问题描述:

I am running a Powershell script that queries MySQL server and displays results in same window. It works fine but the problem is each result is displayed with individual table headers like this -

I would like those results to be displayed in tabular form with headers on the top.

Any suggestions pls?

Thanks!

网友答案:

It looks like your output is being output with format-list. Can you try adding '|format-table' to the end of the last command in your script like:

{all your code to get data } | format-table

For more information on format-table run:

get-help format-table

For information about how PowerShell makes decisions for default formatting of output objects:

get-help about_format

And lastly, you can use 'fl' as a shortcut for format-list and 'ft' as a shortcut for format-table.

网友答案:

It looks to me like that each result is object with properties. I don`t know how is your code written but would say that what you need to do is to create hash table and add each object in to it when it is received.

$Results = @() 

Maybe you`ll need to create object from retrieved data first. if so than use

$RetrievedObject = New-object PSObject -property $RetrievedData

On the end add $RetrievedObject to hash table

$Results += $RetrievedObject - this add object to hash table
相关阅读:
Top