Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group-ObjectFast: Compatibility with standard Group-Object #2

Open
scriptingstudio opened this issue Mar 3, 2020 · 0 comments
Open

Comments

@scriptingstudio
Copy link

scriptingstudio commented Mar 3, 2020

If you group multiple properties standard Group-Object uses ", " (comma + space) as delimiter in the Name field.
Line 42 has an error in join operator argument

$key = $(foreach($_ in $Property) { $InputObject.$_ }) -join ','

It should be

$key = $(foreach($_ in $Property) { $InputObject.$_ }) -join ', '

Test

$data = ConvertFrom-Csv @'
Region,Item,TotalSold
South,melon,47
South,orange,84
West,hammer,81
South,nail,62
East,lime,74
West,pear,88
East,drill,26
South,saw,42
East,kiwi,46
North,banana,2
'@ 

$data | Group-Object Region,item 
Count Name                      Group                                                                                         
----- ----                      -----                                                                                         
    1 South, melon              {@{Region=South; Item=melon; TotalSold=47}}                                                   
    1 South, orange             {@{Region=South; Item=orange; TotalSold=84}}                                                  
    1 West, hammer              {@{Region=West; Item=hammer; TotalSold=81}}                                                   
    1 South, nail               {@{Region=South; Item=nail; TotalSold=62}}                                                    
    1 East, lime                {@{Region=East; Item=lime; TotalSold=74}}                                                     
    1 West, pear                {@{Region=West; Item=pear; TotalSold=88}}                                                     
    1 East, drill               {@{Region=East; Item=drill; TotalSold=26}}                                                    
    1 South, saw                {@{Region=South; Item=saw; TotalSold=42}}                                                     
    1 East, kiwi                {@{Region=East; Item=kiwi; TotalSold=46}}                                                     
    1 North, banana             {@{Region=North; Item=banana; TotalSold=2}}

Moreover, it works incorrectly with multiple properties

$data | Group-ObjectFast -Property Region,item
Count Name         Group                                       
----- ----         -----                                       
    1 North,banana {@{Region=South; Item=nail; TotalSold=62}}  
    1 North,banana {@{Region=East; Item=drill; TotalSold=26}}  
    1 North,banana {@{Region=West; Item=hammer; TotalSold=81}} 
    1 North,banana {@{Region=South; Item=saw; TotalSold=42}}   
    1 North,banana {@{Region=West; Item=pear; TotalSold=88}}   
    1 North,banana {@{Region=South; Item=melon; TotalSold=47}} 
    1 North,banana {@{Region=East; Item=kiwi; TotalSold=46}}   
    1 North,banana {@{Region=East; Item=lime; TotalSold=74}}   
    1 North,banana {@{Region=North; Item=banana; TotalSold=2}} 
    1 North,banana {@{Region=South; Item=orange; TotalSold=84}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant