Last week was “PowerShell Week” in our office*. In an effort to introduce my colleagues to the wonders of PowerShell, I arranged a series of “PowerLunches”, each one lasting an hour and covering a different aspect of PowerShell scripting. Enrolment was open to anyone in the office, and people were free to attend as many of the sessions as they wanted.
The week was a great success, but now I need to send a follow-up email. I have to target it to just the attendees, so can’t just send an office-wide mail. The problem is that all I have are the separate attendee lists for each session (as CSV files), and, since attendance was more-or-less random, there is a lot of duplication between lists:
Attendee Lists
Can you use PowerShell to generate a single list of attendees and email addresses? While making your list, consider these points:
While you’re at it, can you work out who attended the most sessions, and who attended the fewest?
Some hints, if you need them.
* – If any of my colleagues are reading this, no, you didn’t miss out - last week wasn’t “PowerShell Week”. I made that up. Wouldn’t it be great, though?
Here's my one liner:
ls session*.csv | % { $csv += Import-Csv $_ }; $csv | select @{NAME="LN";EXPRESSION={($_.name -split " " | select -last 1)}},name,email -unique | sort ln, name | select name, email | Export-Csv sortedlist.csv
$_.name.Split(' ')[-1]
Duh, why didn't I think of indexing the last item in the array?