4

I would like the Application and ShortcutName columns to be grouped into one column, while keeping the Version and Architecture columns as they are :

$object | Select-Object -Property Application, Version, Architecture, ShortcutName |
  Sort-Object -Property @{expression="Architecture";Descending=$true},Application | 
    Out-GridView

How can I do that ?

mklement0
  • 382,024
  • 64
  • 607
  • 775
A. Joson
  • 89
  • 1
  • 7

1 Answers1

3

In PowerShell you group objects by properties with Group-Object. What you want is not grouping in that sense, but defining a new custom property.

You create custom properties a hashtable with the Name and Expression keys.

Something like this will probably do the trick.

$Expression = {
    if ($_.Application) {
        $_.Application
    } 
    else {
        $_.Shortcut
    } 
}

$object | 
    Select-Object -Property @{ Name = 'Application'; Expression = $Expression }, Version, Architecture | 
    Sort-Object -Property @{expression="Architecture";Descending=$true},Application | 
    Out-GridView

The expression checks whether the Application property is filled. If so, it will use the existing application name, otherwise it will take the Shortcut property as application name.

vrdse
  • 2,899
  • 10
  • 20
  • The Application property is always filled. I don't want substitute the Application property with the Shortcut property but have one column with the content of this 2 properties. – A. Joson Nov 25 '18 at 12:50