r/PowerShell • u/Le-Pygargue • Mar 28 '19
Script Sharing Cat Fact office prank
114
Upvotes
Hey everyone, I saw this cool piece of work on the sub but It wasn't working for me.
I change the script a bit and It works now (for me at least).
It did not have a chance to test the scheduled task bit yet but It would look like this :
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "CatFact.ps1"
$Trigger = New-ScheduledTaskTrigger
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName "AppLog" -Description "Cat fact"And It would execute this :
#$SpeechSynth.GetInstalledVoices().VoiceInfo
Add-Type -AssemblyName System.Speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$SpeechSynth.SelectVoice("Microsoft Zira Desktop")
$Browser = New-Object System.Net.WebClient
$Browser.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$CatFact = (ConvertFrom-Json (Invoke-WebRequest -Verbose -Uri https://catfact.ninja/fact -UseBasicParsing))
$CatFact.fact
$SpeechSynth.Speak("Did you know ?")
$SpeechSynth.Speak($CatFact.fact)Those fact are in English so if your default language is something else the pronunciation would be weird. You can adjust that with something like this :
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$SpeechSynth.GetInstalledVoices().VoiceInfo
#Choose the voice you want from the output. For English it would be the following :
$SpeechSynth.SelectVoice("Microsoft Zira Desktop")Alternatively you can try finding (or even building) a Cat Fact API for your language or running the output through the Google Translate API.
Let me know if something can be improved and if you get some funny stories out of this :)