A 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.
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!
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
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.