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.
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 .
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"
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.
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)]
In v2 you have to assign a value to Mandatory and ValueFromPipeline: Mandatory=$True,ValueFromPipeline=$True
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
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.