PowerShell – Out-GridView Headers with Get-Process
I thought I would do a follow-up on a previous post about using out-GridView with Headers and use Get-Process this time. Although this post is
similar to prior post, I’ve shortened a few things in regards to my collection of header information.
($A = Get-Process) | Out-GridView or OGV
Essentially the $A is creating a variable/collection of items and displays without column names.
Use $A.GetType() and as you see the object type is a collection(System.Array).


At this point $A returns the items that are in the collection including the headers that are automatically created and are the names that will be
used for our header object.

the $A and Get-Process with Out-Gridview/OGV both return the same results with out our extra header information.

Finding Header Information
Discovering what makes up the header can be found by using the following commands.

The first item displays all the available Member Types available for $A.
$A | Get-member -MemberType *
Here is a mini sub-set of items that are displayed. I find it a tad strange that all items were not created as an AliasProperty.

The first 7 items identified as AliasProperty are used as the column headings from $A.
$A | Get-member -MemberType ‘AliasProperty’

$A | Get-member -MemberType ‘ScriptProperty’
Identify Column Names
Headings to be used from Get-member functions are:
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id SI ProcessName
Data to populate the tables arrives in the following form:
Handles AliasProperty Handles = Handlecount
Name AliasProperty Name = ProcessName
NPM AliasProperty NPM = NonpagedSystemMemorySize64
PM AliasProperty PM = PagedMemorySize64
SI AliasProperty SI = SessionId
VM AliasProperty VM = VirtualMemorySize64
WS AliasProperty WS = WorkingSet64
Id Property int Id {get;}
CPU ScriptProperty System.Object CPU {get=$this.TotalProcessorTime.TotalSeconds;}
Running get-help get-process -full returns information about Get-Process.

This shows what the values are for column headings. SessionID does not appear in the help file. ( there is a lot more information then what I’ve displayed)
Now that I’ve shown where the fields are for the headers that will be used for reporting lets build the Report-Header object.
Create an object to hold header values
Creating Heading Object
$TestProperties = new-Object Object
By itself $TestProperties only returns the System.Object

Now lets setup the Properties we want in our object.
add-Member -inputobject $TestProperties -MemberType NoteProperty -Name “Handles” -Value “Handles“
add-Member -inputobject $TestProperties -MemberType NoteProperty -Name “NPM” -Value “NPM(K)“
add-Member -inputobject $TestProperties -MemberType NoteProperty -Name “PM” -Value “PM(K)“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “WS” -Value “WS(K)“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “VM” -Value “VM(K)“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “CPU” -Value “CPU(s)“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “Id” -Value “Id“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “SI” -Value “SI“
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “ProcessName” -Value “ProcessName“
I kept the values in the same order that Get-Process returns.
What I’m doing is creating an initialized array with values that will be used as the header of a report. For this example of working with Report-Headers I’ve used Get-Process to show that it’s pretty darn easy to quickly add report headers for use in OGV or Out-GridView functions.

An Initialized Heading Record
At this point I have an collection/array that contains 1 initialized record of straight text that will be used for Out-GridView.
Without placing the statements into a function here is what you see when running $TestProperties | Out-GridView

There 1 initialized record showing headings. 🙂
Now that there is an initialized collection of header information we can combine $A and $TestProperties and generate our Out-GridView.

Ooops. 🙂 $TestProperties is not the type that allows for joining objects of data together. You’ll need to create your collection/array to something
like this $local:TestCollection = @() But it’s just as easy to create a simple function
Simple Function Report-Headers()
function Report-Headers() {
# There are a few methods for createing objects. Keeping this simple
# to show the possibilities
# Sets up an empty object with header names for use in out-gridview
$local:TestCollection = @()
# Create a new object with the same values as in ($A = Get-Process) to hold header names
$TestProperties = new-Object Object
add-Member -inputobject $TestProperties -membertype NoteProperty -Name “Handles” -Value “Handles”
add-Member -inputobject $TestProperties -membertype NoteProperty -Name “NPM” -Value “NPM(K)”
add-Member -inputobject $TestProperties -membertype NoteProperty -Name “PM” -Value “PM(K)”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “WS” -Value “WS(K)”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “VM” -Value “VM(K)”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “CPU” -Value “CPU(s)”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “Id” -Value “Id”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “SI” -Value “SI”
add-Member -InputObject $TestProperties -MemberType NoteProperty -Name “ProcessName” -Value “ProcessName”
$local:TestCollection += $TestProperties
$global:ReportHeaders = $local:TestCollection
}

I realize that there are similar ways to solve this issue. However this is simple and works.
Display Heading Results
$Global:ReportHeaders | out-gridview


Please keep in mind that I’m not doing any calculations on the field values. This is just a simple method for creating report headers if they are needed.
The data could also be sent directly into an SQL database.
Well that’s it for this post. Comments and suggestions are always welcome.
Thoughts & Ideas, Joseph Kravis 🙂
This article was collaborated on by using chatGPT and images I’ve created with MIDJOURNEY. A fun orchestration by me. 🙂 All images available in higher resolution.
Categories: #kravis, #PowerShell, #programming, PowerShell, PowerShell Posts
Hi Joseph,
thanks a ton for this elaborate update ;).
I have a liking for well done documentations and learned by following along your lead.
Regards,
Dennis