Public/Get-Fortune.ps1
#============================================================================== # GET-FORTUNE # # WRITTEN BY GREGORY F MARTIN (NOT GARY) # # MIMICS THE UNIX 'FORTUNE' COMMAND BY DISPLAYING A RANDOM QUOTE. QUOTES ARE # POLLED FROM THE FORTUNEDATA.TXT FILE IN THE PRIVATE DIRECTORY. #============================================================================== Set-StrictMode -Version Latest <# .SYNOPSIS Displays a random quote from a selected category, mimicking the UNIX 'fortune' command. .DESCRIPTION The Get-Fortune function selects and displays a random quote from one of several categories. Quotes are read from text files located in the Private directory. Each category corresponds to a different file. Quote information is copied from the upstream Fortune repository (http://bxr.su/OpenBSD/games/fortune/). .PARAMETER Category The category of quotes to display. Valid options are 'Sane', 'Insane', 'StarTrek', and 'Zippy'. Defaults to 'Sane'. These categories are of my own choosing and do not reflect any official categorization. .EXAMPLE Get-Fortune Displays a random quote from the 'Sane' category. .EXAMPLE Get-Fortune -Category StarTrek Displays a random quote from the 'StarTrek' category. .NOTES Author: Gregory F Martin .LINK https://github.com/gregoryfmartin/PSFortune #> Function Get-Fortune { Param ( [ValidateSet('Sane', 'Insane', 'StarTrek', 'Zippy')] [String]$Category = 'Sane' ) Process { [String[]]$Quotes = @() Switch($Category) { 'Sane' { $Quotes = Get-Content -Path $PSScriptRoot\..\Private\FortuneData.txt -Delimiter '++'; Break } 'Insane' { $Quotes = Get-Content -Path $PSScriptRoot\..\Private\FortuneData2.txt -Delimiter '++'; Break } 'StarTrek' { $Quotes = Get-Content -Path $PSScriptRoot\..\Private\FortuneDataStarTrek.txt -Delimiter '++'; Break } 'Zippy' { $Quotes = Get-Content -Path $PSScriptRoot\..\Private\FortuneDataZippy.txt -Delimiter '++'; Break } Default { $Quotes = Get-Content -Path $PSScriptRoot\..\Private\FortuneData.txt -Delimiter '++'; Break } } $Quotes[(Get-Random -Maximum $Quotes.Count)] } } |