Get-Quote

1.0

Reads a random quote from a quote file and displays it

Installation Options

Copy and Paste the following command to install this package using PowerShellGet More Info

Install-Module -Name Get-Quote -RequiredVersion 1.0

Copy and Paste the following command to install this package using Microsoft.PowerShell.PSResourceGet More Info

Install-PSResource -Name Get-Quote -Version 1.0

You can deploy this package directly to Azure Automation. Note that deploying packages with dependencies will deploy all the dependencies to Azure Automation. Learn More

Manually download the .nupkg file to your system's default download location. Note that the file won't be unpacked, and won't include any dependencies. Learn More

Owners

Copyright

(c) 2015 Chris Warwick. All rights reserved.

Package Details

Author(s)

  • Chris Warwick

Tags

Quote Cookie Fortune MOTD PowerShell FileStream Seek

Functions

Get-Quote

Dependencies

This module has no dependencies.

Release Notes

Get-Quote

Chris Warwick, @cjwarwickps, January 2012.  This version, November 2015.

Read a Quote/Cookie/Fortune/MOTD from a file and display it.

The fortunes file consists of thousands of random quotes.  As a quote can contain
newline characters, each individual quote is delimited with a 0x00 character; the
delimiter is also present as the first and last character in the file in order to
simplify the parsing below.

Rather than reading the entire file before selecting a random quote the script uses
the FileStream.Seek method to locate and read a randomly-placed small chunk of the
file. A quotes is then selected randomly and extracted from the resutling data.

Bugs: There's no error checking.  The quote file must be ASCII encoded.

Historical Note: The quote file used here is just over 600kB in size. Back in the
day this could have take some considerable time to read from (slow) disk. Now, of
course, with tablets having GBs of memory and SSDs, this size is trivial and the
effort of attempting to read the file efficiently as opposed to simply grabbing the
whole thing with Get-Content is academic.  However, the techniques may still be of
value if truly large files are being processed...
 

Script Help
-----------

<#
.Synopsis
   This function displays a randomly chosen quote from a quote file
.Description
   Displays a random quote/cookie/fortune/message-of-the-day
.Example
   Get-Quote
   I've had a perfectly wonderful evening.  But this wasn't it.
-- Groucho Marx
.Parameter QuoteFile
   A file containing quotes; will use '.\fortunes.dat' by default.
#>


Version History:
---------------

V1.0 (This Version)
 - Initial release to the PowerShell Gallery

V0.1-0.9 Dev versions

Other Modules:
------------
See all my other PS Gallery modules:

 Find-Module | Where Author -match 'Chris Warwick'

FileList

Version History

Version Downloads Last updated
1.5 771 7/18/2017
1.2 344 11/28/2015
1.1 24 11/27/2015
1.0 (current version) 23 11/26/2015