Say I have a simple csv file. The model contains 4 fields id, name, group, and sub. the group field has integer values between 1 and 15 and it can repeat.
So what I am trying to do is select all records not in groups 7 and 9...I've written the below code:
$csv = Import-Csv -Path names.csv -Header @('id', 'name', 'group', 'sub')
$total = $csv | select group -unique
write-host "total:", $total.length
$ignore = $csv | where { $_.sub -eq 'a'}
write-host "total to ignore:", $ignore.length
$ignoreGroups = $ignore | select group -unique
write-host "Groups to ignore:", $ignoreGroups.length
$workingGroups = $csv | where {$ignore -notcontains $_ } | select group -unique
write-host "Working groups count:", $workingGroups.Length
The previous line reports a wrong result.
My goal would be to process the records belonging to $csv one group at a time (i.e group in $workingGroups).
Ps: This is only a model, not the real data. The real data is a huge log file I have to process.
Sample Data: https://gist.github.com/deostroll/4ced74eef461de61f477
Edit:
I am trying to select the distict group values using select-object, but what I am getting is an array of objects (each object with group property). What do I do to get distinct group values alone as an array of integers...?