Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: New-Thriller Revised

Posted on July 12, 2013

bookreaderA few years ago I posted a PowerShell script to autogenerate a synopsis for a standard thriller. It was a lot of fun and demonstrated out to build complex strings using the -F operator. I decided to revisit this script and tweaked it some. The main change is that instead of using the -F operator, which can be a little confusing to beginners, I simply take advantage of variable expansion. Here' the new code.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!
$title = "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" | Get-Random
$name = "Tim Burr","Jack Frost","Paul Bunyan","Roy Biv","Calvin Hobbes","Art Deco","Rocky Cliff","Wes Lathers","Jim Shorts","Wayne Manner" | Get-Random
$first = ($name | Get-Random).Split()[0]
$former = "Navy SEAL","Army Ranger","NASA shuttle astronaut","Green Beret","NSA analyst","Secret Service agent","CIA agent","IT administrator","Delta Team commander" | Get-Random
$villian = "The Society","The Guild","SPECTRE","The Brotherhood","The Guardians","Google","Microsoft","The Illuminati","The Shadow","The Black List","Microsoft","Google","Oracle","Yahoo" | Get-Random
$family = "son","daughter","wife","mother","father","dog","hamster","sister","brother","twin" | Get-Random
$tragedy = "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 failure of Windows Vista" | Get-Random
$mystery = "Clippy","Bieber Fever","who shot J.R.","Google Glass","Macchu Pichu","meatloaf","Atlantis","the missing Mayans","alien abductions","Easter Island","chocolate covered bacon","Anastasia","the Holy Grail","the last pharoah","the secret Pope" | Get-Random
$backdrop = "North Dakota","ancient Egypt","ancient Greece","Istanbul","Redmond","Omaha","Singapore","Antarctica","the Hindu Kush","the Amazon rain forest","Disney World","the Gobi Desert","Newark" | Get-Random -Count 2
$loveInterest = "Sheila","Brandi","Betty","Layla","Emma","Elizabeth","Alice","Rebecca" | Get-Random
$loveBackstory = "a former student","his ex-wife","his mentor's daughter","the librarian","a Harvard symbologist" | Get-Random

$blurb = @"
'$Title' 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 middle of a series of catastrophic events 
unleashed by the sinister organization $villian,
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 $villian, $first and $loveInterest
have but one chance to stop them. But can they do it before 
time runs out?"
"@

#get a random color EXCEPT what is being used for the current background color
$fg= [enum]::GetValues([system.consolecolor]) | where {$_ -notcontains $host.ui.rawui.backgroundcolor} | Get-Random

Write-Host $blurb -ForegroundColor $fg

The first part of the script defines the necessary elements for the story blurb. Each array of items is piped to Get-Random to return a single value. Except for $backdrop which gets 2 random elements from the list. The $blurb variable is a here-string that replaces all the variables with their values. The only tricky one is that the backdrops need a little extra help because $backdrop is an array so I have to use a subexpression.

The other change, which is purely cosmetic and fun, is that I get a random console color and write the blurb to the screen using that color. Because I don't want the color to be the same as the current background color, I filter that value out. It is possible you'll still get some dark colors that are hard to read. But this is just for fun anyway.

Here are some sample thrillers:

'Deep Rising' throws former NASA shuttle astronaut Paul Bunyan in the
middle of an extraordinary adventure that will
push him beyond the breaking point. While on a seemingly
idyllic holiday Paul quickly finds himself trapped
in the middle of a series of catastrophic events
unleashed by the sinister organization The Brotherhood,
that threaten not only his sanity but the very fabric
of society. Haunted by the nightmares of war, Paul must overcome
a complex and diabolic plot surrounding the mystery of
Bieber Fever. Swept up by forces unseen, Emma,
the librarian, is paired with Paul in an uneasy
alliance that will test them both.

Set amidst the exotic backdrops of the Gobi Desert and
Omaha, Paul and Emma will make a
discovery that will change their world and ours, forever.
Hunted relentlessly by The Brotherhood, Paul and Emma
have but one chance to stop them. But can they do it before
time runs out?"

'The Xipher Cipher' throws former Green Beret Tim Burr in the
middle of an extraordinary adventure that will
push him beyond the breaking point. While on a seemingly
idyllic holiday Tim quickly finds himself trapped
in the middle of a series of catastrophic events
unleashed by the sinister organization Microsoft,
that threaten not only his sanity but the very fabric
of society. Haunted by a missing library book, Tim must overcome
a complex and diabolic plot surrounding the mystery of
chocolate covered bacon. Swept up by forces unseen, Betty,
his mentor's daughter, is paired with Tim in an uneasy
alliance that will test them both.

Set amidst the exotic backdrops of Redmond and
Singapore, Tim and Betty will make a
discovery that will change their world and ours, forever.
Hunted relentlessly by Microsoft, Tim and Betty
have but one chance to stop them. But can they do it before
time runs out?"

My next step is to parse the words so that each line is about 80 characters and can break on a word boundary. I started playing with regular expressions to handle this but ran out of time. So maybe another time. Enjoy and happy reading!


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

3 thoughts on “Friday Fun: New-Thriller Revised”

  1. DanielS says:
    July 12, 2013 at 12:38 pm

    Hi Jeff,
    I have tweaked my buffer size in some job logging, this might help:

    #Adjusting the buffer size
    #pshost = get-host
    #$pswindow = $pshost.ui.rawui
    #$newsize = $pswindow.buffersize
    #$newsize.height = 3000
    #$newsize.width = 80
    #$pswindow.buffersize = $newsize

    1. Jeffery Hicks says:
      July 12, 2013 at 12:52 pm

      That’s an interesting approach. But I don’t think this works with a here-string at least as I’ve constructed it. This would work if the line is longer than the buffer size.

  2. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #37 - Dell TechCenter - TechCenter - Dell Community

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d