Hi,
I am trying to union two sets of data and get the distinct values back. The below code gets the top 5 processes by cpu and working set memory and unions the results together. I was expecting a distinct list of processes with the following id’s ( 4, 900, 2536, 3196, 4452, 6924, 7404, 1524) as you can see the processes with the id’s 7404 & 1524 are missing from the last result set that gets a unique set. I can not explain this. Any help would be appreciated.
$process = Get-Process $cpu = $process | Sort-Object CPU -Descending | Select-Object -First 5 $ws = $process | Sort-Object WorkingSet -Descending | Select-Object -First 5 $a = @() $a += $cpu $a += $ws
$cpu NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 629 0 108 308 3 2,802.36 4 System 171 15 15024 21636 106 2,334.49 4452 vmtoolsd 3306 321 615960 772640 1349 1,415.93 900 devenv 313 24 17740 25096 105 1,393.74 2536 vmtoolsd 3558 328 606116 766860 1368 1,356.66 6924 devenv
$ws Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 2969 393 694852 883436 1581 652.15 3196 devenv 2621 341 628636 778132 1430 343.76 7404 devenv 3306 321 615960 772640 1349 1,415.93 900 devenv 3558 328 606116 766860 1368 1,356.66 6924 devenv 2732 344 590188 761144 1390 598.62 1524 de
$a | Sort-Object id | Get-Unique Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName 629 0 108 308 3 2,802.36 4 System 171 15 15024 21636 106 2,334.49 4452 vmtoolsd 3306 321 615960 772640 1349 1,415.93 900 devenv 313 24 17740 25096 105 1,393.74 2536 vmtoolsd 3558 328 606116 766860 1368 1,356.66 6924 devenv