Out-GridView needs a -DisplayProperty parameter
Votes from Connect: 42
Original Date Submitted: 4/10/2015 11:19:28 PM
Handle: Trevor Sullivan [MVP]
Site Name: PowerShell
Feedback ID: 1238786
The Out-GridView command displays all of the properties of each object that is fed into it. Consequently, in order to make the tool more usable, the Select-Object command can be used to inclusively filter the key properties of each object, to display to the end user. Unfortunately, this process results in a modified object, that cannot be used for all intended purposes.
Instead of using Select-Object, a -DisplayProperty parameter should be added to Out-GridView, so that unmodified objects can be piped into it, while only the specified properties are displayed. The pipeline output from Out-GridView should emit the unmodified objects.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 1238786 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1238786).
Internal BugId: 14376
This is something we’d like to fix, but we’re still evaluating at a high-level how to make future improvements to Out-GridView.
David Wilson commented
Thanks for the great example Sebastian! We'll look into this.
Sebastian N. commented
I agree, OGV should indeed output unmodified objects while allowing us to define what should be displayed by the cmdlet.
One of my use cases is PowerCLI where I want to filter snapshots via OGV to pipe them to the Remove-Snapshot cmdlet. In order to see all of the snapshot properties that I want to filter by I need to use select-object prior to piping my snapshots to OGV. That causes the objects to change and loose their type information which makes the Remove-Snapshot cmdlet fails since the input objects from OGV don't match the expected snapshot objects that Get-Snapshot returns, e.g.:
$snapshots = Get-VM | Get-Snapshot
$snapshots | select-object -properties "a","b","c" | Out-GridView -OutputMode Multiple | Remove-Snapshot -confirm:$false -runasync -verbose
Being able to define a list of properties that should be shown by OGV while keeping the original object intact would be a great addition.