Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Created November 16, 2018 14:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdhitsolutions/e65c82a86cbf144df49104e942e0da2a to your computer and use it in GitHub Desktop.
Save jdhitsolutions/e65c82a86cbf144df49104e942e0da2a to your computer and use it in GitHub Desktop.
A fun PowerShell script to generate a thriller book description from random data. Demonstrates a number of scripting techniques.
<#
Examples
PS C:\> c:\scripts\New-Thriller.ps1
Open Source
-----------
by Jack Rollins
This exciting new tale from the author of 'Patch Tuesday' and 'The Game of Death',
throws former ex-mercenary Calvin Hobbes in the middle of an extraordinary adventure that will push
him beyond the breaking point. While on a seemingly idyllic holiday, Calvin quickly finds
himself trapped in the midst of a series of catastrophic events unleashed by the sinister
and shadowy organization known only as The Society, that threaten not only his sanity but the
very fabric of society.
Haunted by the fear of water, Calvin must overcome a complex and diabolic plot surrounding the
mystery of alien abductions. Swept up by forces unseen Layla, a white-hat hacker,
is paired with Calvin in an uneasy alliance that will test them both.
Set amidst the exotic backdrops of Venice and ancient Greece, Calvin and
Layla will make a discovery that will change their world and ours, forever.
Hunted relentlessly by The Society, Calvin and Layla have but one chance to stop them.
Can they do it before time runs out?
Published 16 November 2018
#if running PowerShell Core
PS C:\ c:\scripts\New-Thriller.ps1 -Asmarkdown | Show-Markdown
<you'll see a console version of the markdown document>
#>
Param([switch]$AsMarkdown)
# a private function to add some extra randomization to the process
Function _getitem {
[cmdletbinding()]
Param(
[string[]]$Items,
[int32]$Count = 1
)
#randomize items and then select a random entry
$r = $items | Get-Random -Count $items.count
$r | Get-Random -Count $count
}
#feel free to add your own elements.
$authorPool = "Ben Coes", "Vince Flynn", "Brad Thor", "James Rollins", "Tim Tigner", "Kyle Achilles", "Mitch Rapp", "Dewey Andreas", "James Patterson",
"Blake Crouch", "Jack Ryan", "Dan Brown","Douglas Preston","Scot Harvath","David Baldacci","Lee Child","Lincoln Childs","Tom Clancy"
$titles = "The Omega Plan", "Deep Rising", "The Last Icon", "Exit 1", "The Silver Goose", "The Last Man Standing", "Old MacDonald's Farm", "redrum",
"Running on Empty", "Paradise City", "The Hidden Door", "No Yesterdays", "The Xipher Cipher", "Whiskey Tango Foxtrot",
"The Whisper Man", "Little Jack", "Glock, Rock and Roll", "Kill or Be Killed", "The Blue Room", "The Bourbon Betrayal",
"The Dove", "The Paper Man", "The Deer Spy", "Silent Wind" , "The Enigma Warning" , "The Drive-In", "Ancient Wounds",
"Patch Tuesday", "The Avenger Game", "Chess and Checkers", "The Game of Death", "Mr. Brownstone", "Holy Diver", "Caress of Steel",
"The Meeting", "Scrum", "Open Source", "The OSI Model", "Full Stack", "Protocol", "Room 101","Department Zulu","The Omaha Incident",
"The Forgotten Fight","Pandora's BoxX","Rainbow Run","The Encryption Seed","Packet Protocols","Wireshark"
$names = "Tim Burr", "Jack Frost", "Paul Bunyan", "Roy Biv", "Calvin Hobbes", "Art Deco",
"Rocky Cliff", "Wes Lathers", "Jim Shorts", "Wayne Manner", "Chris Massy", "Alan Fresco", "Chip Shott", "Bobby Bilder", "Carl Marks", "Sandy Bottoms",
"Ben Dover", "Colt Handler", "Thomas Tank", "Chuck Stakes", "Jack Spratt"
$formers = "Navy SEAL", "Army Ranger", "NASA shuttle astronaut", "Green Beret", "NSA analyst", "Secret Service agent", "CIA agent",
"IT administrator", "Delta Team commando", "Special Forces operator", "county sheriff",
"high-school math teacher", "first year law student", "Army vet", "ex-mercenary", "FBI agent", "detective", "forensic investigator",
"LA County Coroner","stuntman","bodyguard","security specialist","hacker","romance novelist"
$villains = "The Society", "The Guild", "GHOST", "The Brotherhood", "The Guardians", "Google", "The MicroMen", "The Illuminati",
"The Shadow", "The Black List", "The Book of Faces", "The Deep State", "The Dark Council", "Purple Rain", "The Black Table",
"The Red Masque","The Alliance","Hydra","The Committee","The Change Control Board", "The Corner Office","The Department","The Judges"
$members = "son", "daughter", "wife", "mother", "father", "dog", "hamster", "sister", "brother", "twin", "uncle", "grandmother",
"partner", "lover", "mentor", "girl friend","child hood friend","professor"
$tragedies = "the tragic loss of his $family", "the nightmares of war", "a missing library book", "a toothache",
"a fear of flying", "the Cubs losing record", "the fear of water", "climate change", "the fear of missing out", "a childhood tragedy"
$mysteries = "Clippy", "Bieber Fever", "who shot J.R.", "Microsoft HoloLens", "Machu Picchu", "meatloaf",
"Atlantis", "the missing Mayans", "alien abductions", "Easter Island", "chocolate covered bacon", "Anastasia", "cloud services", "daylight savings time",
"womens' dress sizes", "his lost car keys", "the golden fleece", "the other Rembrandt", "the elf on the shelf", "Microsoft licensing",
"the Holy Grail", "the Last Pharoah", "the secret Pope", "the alternate President", "the secret stash", "the Kardashians", "of Yammer"
$backdrops = "North Dakota", "ancient Egypt", "ancient Greece", "Istanbul", "Redmond", "Omaha", "Singapore", "Antarctica",
"the Hindu Kush", "the Amazon rain forest", "Disney World", "the Gobi Desert", "Newark", "Poughkeepsie", "Paris", "the Acropolis",
"the Taj Mahal", "Angkor Wat", "Sri Lanka", "Venice", "Tulsa","the Arctic tundra","the catacombs of Rome","the Kremlin","Indianapolis"
$loveInterests = "Sheila","Brandi","Betty","Wilma","Layla","Emma","Elizabeth","Alice","Rebecca","Kitty","Kandy","Danielle","Rose",
"Ethel","Gertie","Beth","Honey","Alexa","Siri","Dory","Daphne","Esther","Jessica","Missy","Paula","June","Jenny"
$loveBackstories = "a former student", "his ex-wife", "his mentor's daughter", "the librarian", "a Harvard symbologist",
"a struggling actress", "a diner waitress", "a college professor", "a single-mom", "a paralegal", "a nursing student",
"a linguist", "an art historian", "a cryptographer", "an audiologist", "a speech-language pathologist", "a pet psychic",
"large animal veterinarian", "a Starbucks barista", "a fashion model", "a .NET developer", "a woman with a deadly secret",
"a barkeeper","a photo-journalist","police sketch artist","a white-hat hacker"
#get 3 titles. The first will be the new title and the remaining, past titles for
#the generated author
$title = _getitem $titles -Count 3
$name = _getitem $names
#get the hero's first name
$first = ($name | Get-Random).Split()[0]
$former = _getitem $formers
$villain = _getitem $villains
$family = _getitem $members
$tragedy = _getitem $tragedies
$mystery = _getitem $mysteries
$backdrop = _getitem $backdrops -Count 2
$loveinterest = _getitem $loveInterests
$loveBackStory = _getitem $loveBackstories
$authornames = _getitem $authorPool -Count 2
#create a random author name by combining the first and last names of
#2 names from the author pool
$author = "$($authornames[0].split()[0]) $($authornames[1].split()[1])"
<#
create a here string for the book's description, using variable
replacement to fill in the blanks. The string also has placeholders
{0} and {1} to demonstrate how to use the -f operator.
#>
#create a custom date format using the day, full month name and year
$pubDate = Get-Date -Format "dd MMMM yyyy"
$blurb = @"
This exciting new tale from the author of {0} and {1},
throws former $former $Name in the middle of an extraordinary adventure that will push
him beyond the breaking point. While on a seemingly idyllic holiday, $first quickly finds
himself trapped in the midst of a series of catastrophic events unleashed by the sinister
and shadowy organization known only as $villain, that threaten not only his sanity but the
very fabric of society.
Haunted by $tragedy, $first must overcome a complex and diabolic plot surrounding the
mystery of $mystery. Swept up by forces unseen $loveinterest, $loveBackStory,
is paired with $first in an uneasy alliance that will test them both.
Set amidst the exotic backdrops of $($backdrop[0]) and $($backdrop[1]), $first and
$loveInterest will make a discovery that will change their world and ours, forever.
Hunted relentlessly by $villain, $first and $loveInterest have but one chance to stop them.
Can they do it before time runs out?
"@
if ($AsMarkdown) {
$out = @"
# $($Title[0])
## by $author
$($blurb -f "[$($title[1])]()","[$($title[2])]()")
### Published $pubDate
"@
}
else {
$out = @"
$($Title[0])
$("-" * ($title[0].length))
by $author
$($blurb -f "'$($title[1])'","'$($title[2])'")
Published $pubDate
"@
}
$out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment