Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: View Objects in a PowerShell GridList

Posted on May 24, 2013

One of the things that makes PowerShell easy to learn is discoverability. Want to know more about a particular type of object? Pipe it to Get-Member. Or if you want to see values pipe it to Select-Object.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!
get-ciminstance win32_computersystem | select *

That's not too bad. Or you can pipe to Out-Gridview.

Get-CimInstance win32_computersystem | Select * | out-gridview

However, for a single object it isn't easy to see everything .
Select-OutGridView

What would be easier, at least for me, is to use Out-Gridview but see the properties in a list like I can with Select-Object. So I wrote an advanced function to do just that. The function takes an incoming object, creates a hashtable based on the object's properties and then displays the hashtable in Out-Gridview.

Function Out-GridList {
[cmdletbinding()]

Param(
[Parameter(Position=0,Mandatory,ValueFromPipeline)]
[object]$InputObject,
[string]$Title="Out-GridList",
[switch]$Passthru
)

Begin {
  #initialize data array
  $data=@()
}
Process {
#initialize a hashtable for properties
$propHash = @{}
#get property names from the first object in the array
$properties = $InputObject | Get-Member -MemberType Properties

$properties.name | foreach {
Write-Verbose "Adding $_"
  $propHash.add($_,$InputObject.$_)
  
} #foreach

  $data +=$propHash

} #Process

End {

#tweak hashtable output
$data.GetEnumerator().GetEnumerator() | 
select @{Name="Property";Expression={$_.name}},Value |
Out-GridView -Title $Title -PassThru:$Passthru
}

} #end Out-Gridlist

The function will accept multiple objects, which is why I have a data array to handle multiple piped in objects. But it really works best with a single object. In the Process scriptblock I pass the object to Get-Member to retrieve properties. Then the function creates a hashtable where the key is each property and the value is the corresponding value from the object.

At this point I could simple write the hashtable to Out-Gridview, but the column headings would say Name and Value. It's a small detail but I use a hashtable with Select-Object to rename "Name" to "Property". By the way, you may have noticed this line.

$data.GetEnumerator().GetEnumerator() 

That isn't a typo. If I pipe multiple objects, then $data will be an array of hashtables and so I need to get an enumerator for each one. But with this function now I get the display I want.

get-ciminstance win32_computersystem | select * | out-gridlist -title "Win32_Computersystem"

OutGridList

There really isn't any filtering to do but you can click on the column headings to sort. Or your can run Out-Gridlist with -passthru so you can select properties and pass them through to the pipeline.

I hope you find this useful. Enjoy responsibly.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

6 thoughts on “Friday Fun: View Objects in a PowerShell GridList”

  1. mikef2691 says:
    May 24, 2013 at 5:26 pm

    I am still on Ver 2
    I have tried changeing the (Position=0, to Position = 0 but no luck. I still get this error.

    The “=” operator is missing after a named argument.
    At line:4 char:35
    + [Parameter(Position = 0,Mandatory, <<<< ValueFromPipeline)]

    1. Jeffery Hicks says:
      May 24, 2013 at 5:33 pm

      In v2 you have to assign a value to Mandatory and ValueFromPipeline: Mandatory=$True,ValueFromPipeline=$True

  2. Laerte Junior says:
    May 26, 2013 at 6:57 pm

    Jeff, a question my friend. You told “The function will accept multiple objects, which is why I have a data array to handle multiple piped in objects.”.
    You are meaning by pipeline right ? Otherwise the $InputObject parameter need to be [Object[]] right ?
    Thanks Sir

    1. Jeffery Hicks says:
      May 27, 2013 at 9:10 am

      Yes. As written, if I tried this: out-gridlist -input $stuff it would only process the first object. But since this is an OUT command I didn’t bother.

  3. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #30 - TechCenter - Blog - TechCenter – Dell Community
  4. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #30 - Dell TechCenter - TechCenter - Dell Community

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d