#vBrownBag Contest – Adventures in PowerShell

Cody blogged earlier regarding his Python solution to easily and fairly identifying #vBrownBag lottery winners. I chose to go the PowerShell route, but more as a fun little thing to do than anything. Ultimately it was Cody’s code that picked the winners. So here’s my solution using PoSH.

$spreadsheet = Import-Csv c:\Users\damian\Desktop\vBrownBag_Giveaway.csv
$prizes = @{"Trainsignal" = 2;"VMwarePress" = 10;"ScottLowe" = 1;"JoshAtwell" = 1; "Sybex" = 5;"VMTurbo" = 2;"EMC" = 1;"Veeam" = 1;"VMware" = 1;"Nutanix" = 5;"Zerto" = 1}
$entries = @{}
foreach ($prize in $prizes.Keys) {
	$entries[$prize] = $spreadsheet | Where-Object {$_.$prize -ne ""} | Select-Object Name
	Write-Host Number of entries for $prize : ($entries[$prize]).count
}
foreach ($prize in $prizes.Keys) {
	$i = 1
	do {
	$winner = Get-Random -Maximum ($entries[$prize]).count
	Write-Host $prize : $entries[$prize][$winner].Name
	$i++
	} while ($i -le $prizes.$prize)
}

To be fair, while Cody’s used some algorithms for de-duping the data, I chose to use Excel’s conditional formatting to identify duplicate entries. This allowed me to either 1.) delete the exact duplicates, and 2.) merge the duplicates that had different picks. In almost all the cases of the latter, the later entries had more things picked. I’m assuming that the contestant decided to change up his or her entry, as the Google Form we used had no capability of remembering submissions. There were a number of folks who submitted using different emails (one using a personal account, the other using a professional account), but I think I did a pretty decent job of identifying those and weeding them out. Nick Marshall also contributed quite a bit by watching the entries and winnowing out the dupes as they came in.

Here’s the breakout per giveaway item:
Number of entries for EMC : 276
Number of entries for Trainsignal : 201
Number of entries for Veeam : 263
Number of entries for VMware : 145
Number of entries for VMwarePress : 232
Number of entries for Sybex : 282
Number of entries for JoshAtwell : 136
Number of entries for Nutanix : 101
Number of entries for VMTurbo : 176
Number of entries for Zerto : 96
Number of entries for ScottLowe : 201

One thought on “#vBrownBag Contest – Adventures in PowerShell”

Comments are closed.