Powershell Secret Santa, sent via Android SMS

For the last few years my wife has been responsible for organising her office Secret Santa. I suggested she use an online tool to assign and notify her colleagues of their assigned gift recipient, but after a brief review of the top google results, it seemed that most solutions were designed to force advertising upon you and not be of much help otherwise.

I decided I could do better. Firstly, she works for the NHS. I have a lot of respect for the NHS, but they are notoriously terrible at IT. So email was out – SMS seemed the best way to go with these guys.
Last year I wrote a script that gave me a list of names & numbers to text, which I then copied and pasted into my phone – total tedium.

This year I decided I should go one better, and have all the work done for me.
The prerequisites of using this are twofold.

Firstly, you must have an android phone, connected via USB to your PC, with debugging enabled and have ADB installed and available in powershell.
I used this guide and despite not having used ADB since I still had long luscious locks, found the process satisfyingly simple.
With that done, run ‘adb devices’ and so long as it lists a device you’re connected.

The second prerequisite is to not comment on my formatting/best practices in powershell; this is purely for a one off (until next year at least) and has done the job very nicely thank you.

Add each person/number you require, run the script and you should be away. The system should assign a person randomly, and avoid duplication or assigning a person to themselves.

function Create-Person {
    param(
        [string]$Name, [string]$Number
    )

    $Person = New-Object System.Object
    $Person | Add-Member -type NoteProperty -name Name -value $Name
    $Person | Add-Member -type NoteProperty -name Number -value $Number
    return $Person
}

function Send-SMS
{
    param([string]$Number, [string]$message)

    adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 $Number s16 "null" s16 $message s16 "null" s16 "null"
}

$People = @()

$People += Create-Person Fred 07234555111
$People += Create-Person Colin 01712232098
$People += Create-Person 'Fred K' 07431987457
$People += Create-Person Susan 0794282342

$AvailablePeople = {$People}.Invoke()

foreach ($Person in $People)
{
    do {
        $RecipientNumber = Get-Random -Maximum $AvailablePeople.Count
    } while ($AvailablePeople[$RecipientNumber].Name -eq $Person.Name)
    $Recipient = $AvailablePeople[$RecipientNumber]
    $Message = 'For\ this\ years\ secret\ santa\ you\ are\ buying\ a\ gift\ for....' + $Recipient.Name
    Write-Host $Message '|' $Person.Name
    send-sms $Person.Number $Message
    $AvailablePeople.RemoveAt($RecipientNumber)
}

2 thoughts on “Powershell Secret Santa, sent via Android SMS

  1. Pingback: ICYMI: PowerShell Week of 27-November-2020 & 04-December-2020 | PowerShell.org

  2. Pingback: ICYMI: PowerShell Week of 27-November-2020 & 04-December-2020 – 247 TECH

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.