PowerShell – Out-GridView Headers

I’ve liked the simplicty of PowerShell when using the Out-GridView against a data set when you want a quick sortable list.

If you use Out-GridView most likely you’re cutting and pasting into an Excel sheet

Out-GridView dosen’t allow you to copy the header row. But, a simple process will help

For example:

From example #4 on this page. https://technet.microsoft.com/en-us/library/hh849920.aspx

($A = Get-ChildItem -Path $pshome -Recurse) | Out-GridView

This displays the header bar but you’re unable to copy this header directly that I’ve not found.


CTRL+A and no grid headers selected.


Now create a simple object and function to run for storing header values:

$global:ReportHeaders = @()

function Report-Headers() {
 # There are a few methods for createing objects. Keeping this simple
 # to show the possibilities

# Sets up dummy object with headers for use in out-gridview
 $local:TestCollection = @()
 $TestProperties = new-Object Object
 add-Member -inputobject $TestProperties -membertype NoteProperty 
-Name "Mode" -Value ""
 add-Member -inputobject $TestProperties -membertype NoteProperty 
-Name "LastWriteTime" -Value ""
 add-Member -inputobject $TestProperties -membertype NoteProperty 
-Name "Length" -Value ""
 add-Member -InputObject $TestProperties -MemberType NoteProperty 
-Name "Name" -Value ""

$TestProperties.Mode = "Mode"
 $TestProperties.LastWriteTime = "Last Write Time"
 $TestProperties.Length = "Length"
 $TestProperties.Name = "Name"
 $local:TestCollection += $TestProperties
 $global:ReportHeaders = $local:TestCollection

 ($A = Get-ChildItem -Path $pshome -Recurse) | Out-GridView
 $global:ReportHeaders +=  $a
 $global:ReportHeaders | Out-GridView

Now there are simple headers to copy into excel or other tools.


Sample Excel:


Well, something very simple. If you’ve found a different way to do this please let me know.


Categories: PowerShell Posts, Technology

Tags: , , ,

5 replies

  1. Hi Joseph,

    I like your workaround!
    And I am a bit confused as how to put your suggestion into action.
    Could you elaborate a bit more how to get from your example to a working solution for any request to Out-GridView?

    Thanks a ton,


  2. Dear Joseph,

    I wanted to put your nice workaround into action but wasn’t able to do so.
    I tried to execute parts of your script but I can’t get it to work with arbitrary headers.

    Could you elaborate a bit more, what steps to follow to get those headers included?



    • Hi Dennis,
      This solution will fit into most any scenario. What are you trying to do and I can show you how to put this into play for you.
      Thank you,


      • Hi Joseph,
        thanks for your quick response!
        I want to have the headers in the list when I am doing e.g.
        Get-Process | ogv
        I tried to define the array like you did before and tried to paste parts of your script into the shell, but to no avail.
        Can you give me a little bit more step by step instructions ;)?


      • Hi Dennis,
        Please look at a new post I’ve created with further explanations. PowerShell – Out-GridView Headers (Using Get-Process)
        on creating simple report headers.
        Thank you,


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


My Dark Life

Mes Mots

Poems, Travelogue, Writeups & more by Sazz!


From a dark home, To an empty soul, A hurt heart, Makes a writer gold.

Ushma Patel

When the green woods laugh with the voice of joy, And the dimpling stream runs laughing by; When the air does laugh with our merry wit, And the green hill laughs with the noise of it.

Leesa Love's Legacy

Spewing my Truth - Poetically


Second life fashion

Loly Hallison

"In moments of crisis, only the imagination is more important than the knowledge" Albert Einstein

%d bloggers like this: