Created
November 13, 2019 16:53
-
-
Save dmissp/e5ab7f47b2deb0c4dc625d1dc5287253 to your computer and use it in GitHub Desktop.
Grab a random catfact from catfact.ninja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get-catfact { | |
<# | |
.SYNOPSIS | |
Grab a random catfact from catfact.ninja. | |
.DESCRIPTION | |
Grabs a random catfact from catfact.ninja and either says it using speechsynth, or displays to the screen. | |
.PARAMETER say | |
Speaks the cat fact | |
.EXAMPLE | |
ps>get-catfact | |
Cats are man's adorable little serial killers. | |
#> | |
param ( | |
[switch]$say | |
) | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 | |
$catfact = (convertfrom-json (Invoke-WebRequest -UseBasicParsing -Uri https://catfact.ninja/fact)).fact | |
if ($say) { | |
Add-Type -AssemblyName System.Speech | |
$global:SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer | |
$global:SpeechSynth.Speak("did you know?") | |
$global:SpeechSynth.Speak($CatFact) | |
} | |
else { | |
$catfact | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment