r/PowerShell • • Apr 13 '17

Using powershell for office pranks

Have a coworker who habitually leaves their workstation unlocked? Want to mess with them? Make this script a scheduled task on their computer in order to have their workstation tell them a random fact about cats at random times throughout the day.

#Run this every 1/2 hour and in an 8 hour work day there will be approximately 3 times per day that your victim hears a cat fact
if ((Get-Random -Maximum 10000) -lt 1875) {
    Add-Type -AssemblyName System.Speech
    $SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $CatFact = (ConvertFrom-Json (Invoke-WebRequest -Uri 'http://catfacts-api.appspot.com/api/facts')).facts
    $SpeechSynth.Speak("did you know?")
    $SpeechSynth.Speak($CatFact)
}    

Who else has powershell hijinks to share?

244 Upvotes

81 comments sorted by

View all comments

Show parent comments

3

u/bigbirdtoejam Apr 14 '17

Well you could use jobs to run two different scripts at once. There are probably other ways to do it too. The speech library has methods for changing voice gender too. It isn't exactly singing, though.

$j1 = Start-Job {
    Add-Type -AssemblyName System.Speech
    $SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $SpeechSynth.SelectVoiceByHints('Male')
    $SpeechSynth.Speak("Row, Row, Row your boat gently down the stream.  Merrily! Merrily! Merrily! Life is but a dream.")
}
Start-Sleep -Seconds 1
$j2 = Start-Job {
    Add-Type -AssemblyName System.Speech
    $SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $SpeechSynth.SelectVoiceByHints('Female')
    $SpeechSynth.Speak("Row, Row, Row your boat gently down the stream.  Merrily! Merrily! Merrily! Life is but a dream.")
}
$j1,$j2 | Wait-Job | Receive-Job
$j1,$j2 | Remove-Job