Typically, when you output a single object to Out-GridView, you get one line, and every property surfaces as a column:

Get-ComputerInfo | Select-Object -Property * | Out-GridView

This makes it hard to view and filter for specific information. Simply convert an object to an ordered hash table to show it as a table inside a grid view window. As a side effect, you can now also eliminate empty properties and make sure properties are sorted:

# make sure you have exactly ONE object
$info = Get-ComputerInfo
# find names of non-empty properties
$filledProperties = $info.PSObject.Properties.Name.Where{![string]::IsNullOrWhiteSpace($info.$_)} | Sort-Object
# turn object into a hash table and show in a grid view window
$filledProperties | ForEach-Object { $hash = [Ordered]@{} } { $hash[$_] = $info.$_ } { $hash } | Out-GridView

This approach works perfectly as long as $info contains exactly one object. For example, you can adjust the code and use “Get-AdUser -Identify SomeName -Properties *” in place of “Get-ComputerInfo” to list all Active Directory attributes for a given user. Just make sure you target exactly one user.

Since this approach turns objects into key-value pairs, it is not suited for multiple objects.




Twitter This Tip! ReTweet this Tip!

Anonymous