Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Get-unique items from an array

$
0
0

Thank you both Simon and Rob,

Both solutions worked for me. Simon I cant believe that I didn't try:

$a | Select-Object 'Handles', 'NPM', 'PM', 'WS', 'VM', 'CPU', 'Id', 'ProcessName' -Unique

I had previously tried :

$a | Select-Object  -Unique 'Handles', 'NPM', 'PM', 'WS', 'VM', 'CPU', 'Id', 'ProcessName'

which did not work for me.

Rob I didn't even know that I could use -unique on a sort. That worked really well as using the select-object method did what I wanted but messed up the formatting which required me to format the table using expressions to tidy things back up.

$a | Select-Object 'Handles', 'NPM', 'PM', 'WS', 'VM', 'CPU', 'Id', 'ProcessName' -Unique | 
        Format-Table @{n='Handles'; ex={$_.Handles}; align='right'; width=10} ,
                     @{n='NPM'; ex={$_.NPM}; align='right'; width=7}, 
                     @{n='PM'; ex={$_.PM}; align='right'; width=15}, 
                     @{n='WS'; ex={"{0:N2}" -f $_.WS}; align='right'; width=17},
                     @{n='VM'; ex={$_.VM}; align='right'; width=15}, 
                     @{n='CPU'; ex={"{0:N2}" -f $_.CPU}; align='right'; width=12},
                     @{n='Id'; ex={$_.Id}; align='right'; width=7}, 
                     @{n='ProcessName'; ex={$_.ProcessName}; align='right'; width=20} -wrap

vs

$a | sort-object id -Unique

Once again thanks both of you. I learned something new today.


Viewing all articles
Browse latest Browse all 13067

Trending Articles