How to use my own data for Out-GridView?

Welcome Forums General PowerShell Q&A How to use my own data for Out-GridView?

Viewing 4 reply threads
  • Author
    Posts
    • #207108
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member

      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

    • #207141
      Moderator
      Topics: 3
      Replies: 218
      Points: 1,188
      Helping Hand
      Rank: Community Hero

      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

      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 

      Thank you.

      • This reply was modified 3 months ago by Kiran.
      • This reply was modified 3 months ago by Kiran.
    • #207825
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member

      thx @ Kiran 🙂

    • #207834
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member

      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

    • #207981
      Participant
      Topics: 4
      Replies: 13
      Points: 49
      Rank: Member

      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

Viewing 4 reply threads
  • You must be logged in to reply to this topic.