Skip to content

Instantly share code, notes, and snippets.

@dmissp
Created November 13, 2019 16:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmissp/e5ab7f47b2deb0c4dc625d1dc5287253 to your computer and use it in GitHub Desktop.
Save dmissp/e5ab7f47b2deb0c4dc625d1dc5287253 to your computer and use it in GitHub Desktop.
Grab a random catfact from catfact.ninja
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