
Group-Object is magic !
I had to create a script that sort a whole csv, each line is an extract of a computer scan, one extract per day, and get only the last extract per computer AND per user.
Indeed, a user can use multiple computers, and several users can use the same computer, the extract result is not the same !
Here is the line that “saved” me :
Import-Csv $file -delimiter ";" | Group-Object 'Username','Computer' | Foreach-Object{ $_.Group | Sort "Last Update" -Descending | Select -First 1} | Sort 'Username','Computer' Export-Csv $DestFile -NoTypeInformation
That line while sort that perfectly, and export to the destination csv all fields.
It’s like sorting M&M’s regarding their expiration date !