How to use my own data for Out-GridView?

It is possible to pipe Powershell-Table outputs to Out-GridView like

Get-Process | Out-GridView
or
Get-ChildItem | Out-GridView
But how do I bring my own data to Out-GridView? For example a
Get-ChildItem > zz.txt Get-Content .\zz.txt | Out-GridView
have only one column called "String".

How can I create my own column names and fill the table?

Greetings
theuserbl

When you redirect the output to a file by default it will be converted to string, so when you retrieve the data from the file using the Get-Content then each line will be a string and when you pass it to Out-GridView it will be only in one column.

And on top of it, some CmdLets produce the output with some hidden properties as well, so you have to export the required properties to the file.

For your requirement you can export the data to CSV and then import the CSV data to Out-GridView

[pre]Get-ChildItem | Select-Object -Property Mode, LastWriteTime, Length, FullName | Export-Csv -Path C:\Temp\zz.txt
Import-Csv -Path C:\Temp\zz.txt | Out-GridView [/pre]

Thank you.

thx @ Kiran :slight_smile:

And how can I set the data type of a column?

I have tried out your example. The difference is, that getting direct the information from Get-ChildItem, the “Length”-column have numbers. But the way over CSV, the “Length”-column are Strings.

You recognize it, if you sort the table in GUI-mode by length.

Normal:

1
2
44
151
345

With CSV:

1
151
2
345
44

Greetings
theuserbl

More generally, Out-Gridview expects an object, such as a pscustomobject, as input. Creating a pscustomobject can be as simple as:
$CustomObject = [PSCustomObject]@{a=1;c=3;b=2;d=4}
$CustomObject | Out-Gridview